我今天刚从require.js开始。我计划创建一个模块,并成功地创建了一个模块。
现在,我想对模块中的返回函数进行递归调用。怎么做?
我的模块。
define(['jquery', 'underscore'], function ($, _) {
var thisModule = this;
return {
moduleFuntion: function (data) {
//Code
...
//How to call moduleFunction here.
}
}
});我试过了
modelFunction();和
thisModule.moduleFuntion();我认为将代码分解成另一个函数,而不是返回函数,并对其进行递归工作。
define(['jquery', 'underscore'], function ($, _) {
var thisModule = this;
function codeFunction(data) {
//Code
....
codeFunction()
}
return {
moduleFuntion: function (data) {
codeFunction(data);
}
}
});但在我目前的代码中,这是可能的吗?
更新:
我已经通过
define(['jquery', 'underscore'], function ($, _) {
return {
moduleFuntion: function (data) {
//Code
...
var moduleObject = require('jsonviewer');
moduleObject.moduleFuntion(dataNew);
}
}
});这是正确的做法吗?
注:我是新来的,所以我想征求专家对我走的路的意见
发布于 2014-06-25 06:54:31
我会在命名函数表达式上重述一遍。
define(['jquery', 'underscore'], function ($, _) {
var thisModule = this;
return {
moduleFuntion: function moduleFunc(data) { // give this function expression a name
//Code
...
//How to call moduleFunction here.
// Now you can call moduleFunction using moduleFunc:
moduleFunc(...);
}
}
});https://stackoverflow.com/questions/24401296
复制相似问题