I have a function that is calling a jquery plugin function by first loading the plugin with RequireJS the problem is the plugin function inside requirejs only gets executed after my function already returned so hasMessageParent always returns null. I'm really confused because this was working fine before and I don't know what change and broke. How can I fix so myMsg gets set to the function return before continuing?
hasMessageParent: function() {
var myMsg = null;
var ctrl = '#myDiv';
require(["my_msgcheck"], function() {
// this gets executed after the return already happened, it returns true
myMsg = $(ctrl).msg_check('hasMessage');
});
// this always returns null because the require jquery plugin function is executed after the return already happened
return myMsg ;
},