node.js - My javascript module is not working when I used gulp and browserify -


my javascript module not working when concat javscript files gulp , browserify.

this module.

lastestpost.js

var postbox = require('../objects/postbox');  var lastestposts = (function() {     var btnleft;     var btnright;      var postboxs = (function() {         var arr = new array();         (var i=0; i<4; i++) {             var post_box = new postbox();             arr.push(post_box);         }         return arr;     })();      var index = 0;     var lastindex;       return({         initdom: function($) {             btnleft = $('#btn-lastest-previous');             btnright = $('#btn-lastest-next');             /* codes */         },         initindex: function() {             if (index == 0) {                 /* codes */             }             else if (index == lastindex) {                 /* codes */             }             else {                 /* codes */             }         },         getlastindex: function() {              $.get('/lastestposts-getlastindex', function(data) {                 lastindex = data;              });         },         updatepostbox: function() {             var parameter = { index: index };              $.get('/lastestposts-getindex', parameter, function(data) {                 /* codes */             });         },         increaseindex: function() {             if (index < lastindex) {                 index++;              }          },         decreaseindex: function() {             if (index > 0) {                 index--;             }          },         getleftbtn: function() {              return btnleft;         },         getrightbtn: function() {             return btnright;         }     });  })();   module.exports = lastestposts; 

main.js

var lastestposts = require('./module/lastestposts');  $(document).ready(function() {      lastestposts.initdom($);     lastestposts.getlastindex();     lastestposts.updatepostbox();     lastestposts.initindex();      (lastestposts.getrightbtn()).click(function() {         lastestposts.increaseindex();         lastestposts.initindex();         lastestposts.updatepostbox();     });     (lastestposts.getleftbtn()).click(function() {         lastestposts.decreaseindex();         lastestposts.initindex();         lastestposts.updatepostbox();     }); }); 

btnleft , btnright clicks well, lastestposts.increaseindex() , lastestposts.initindex() not working.

before using gulp , browserify, import each of javascript files this.

<script src="./js/objects/postbox.js"></script> <script src="./js/module/lastestposts.js"></script> <script src="./js/main.js"></script> 

this works well, after concat javascript files gulp , browserify, javascript module doesn't work...

this gulp setting.

gulp.task('build-js', function () {     return browserify('./public/src/js/main.js')         .bundle()         .pipe(source('bundle.js'))         .pipe(gulp.dest('./public/dist/js')); }); 

please little student , sorry terrible english skill. i'm not @ english :'(

not sure things went wrong you, issue came down error in terminal -

express deprecated res.send(status): use res.sendstatus(status) instead app.js:107:9 

which meant problem specific function not returning lastindex:

getlastindex: function() {     $.get('/lastestposts-getlastindex', function(data) {         lastindex = data;     }); }, 

if modify res.send(4) res.send({lastindex: 4}); , getlastindex() to

getlastindex: function() {     $.get('/lastestposts-getlastindex', function(data) {         lastindex = data.lastindex;     }); }, 

not sure why working prior - lastindex private variable undefined breaking - , why.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -