最初に RequireJS でプラグインをロードしてjqueryプラグイン関数を呼び出す関数があります。問題は、関数が既に返された後にのみ requirejs 内のプラグイン関数が実行されるため、hasMessageParent は常に null を返します。これは以前はうまく機能していたので、何が変わって壊れたのかわからないので、本当に混乱しています。続行する前に myMsg が関数 return に設定されるように修正するにはどうすればよいですか?
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 ;
},