javascript - requirejs loading my jquery plugin async -


i have function calling jquery plugin function first loading plugin requirejs problem plugin function inside requirejs gets executed after function returned hasmessageparent returns null. i'm confused because working fine before , don't know change , broke. how can fix mymsg gets set function return before continuing?

hasmessageparent: function() {     var mymsg = null;     var ctrl = '#mydiv';     require(["my_msgcheck"], function() {         // gets executed after return happened, returns true         mymsg = $(ctrl).msg_check('hasmessage');     });     // returns null because require jquery plugin function executed after return happened     return mymsg ; }, 

you can't fix modifying function alone, have add "my_msgcheck" define call of module.

another option use callback if want load inside function. sign of bad code structure.

var hasmessageparent = function(callback) {     var mymsg = null;     var ctrl = '#mydiv';     require(["my_msgcheck"], function() {         // gets executed after return happened, returns true         mymsg = $(ctrl).msg_check('hasmessage');         callback(mymsg);     }); }; hasmessageparent(function (msg) {     // ... }); 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -