我有两个内部函数的对象。第一个工作完美,但第二个返回错误比“helper.calc.add不是一个函数”。怎么了?JS。对象函数返回函数返回
例如第一:
var calc = (function() {
var add;
var remove;
// some functions add and remove...
return {
add: add,
remove: remove
}
})();
calc.add(1);
其次:
var helper = (function() {
return {
calc: function() {
var add;
var remove;
// some functions add and remove...
return {
add: add,
remove: remove
}
}
}
})();
helper.calc.add(1);
在控制台:
1
Uncaught TypeError: helper.calc.add is not a function
小提琴:https://jsfiddle.net/pk4tsnnt/
'helper.calc'是'function',不'object' ...尝试'helper.calc() .add(1);' – Rayon
您可能打算立即调用函数'calc'。 – RemcoGerlich