0
你好,我发现计算器如何调用动态功能的物品:调用动态jQuery函数
function mainfunc(func) {
this[func].apply(this, Array.prototype.slice.call(arguments, 1));
}
这是非常有用的。但是我怎样才能在我的对象函数中调用一个函数?
我得到一个错误:
"TypeError: this[func] is undefined this[func].apply(this, Array.prototype.slice.call(arguments, 1));"
它看起来像:
var myScript = {
...
add : function() {
...
myScript.ajax('url.php', params, 'myScript.add2List');
},
add2List : function(data) {
console.log(data);
},
ajax : function(url, params, func) {
$.ajax({
type: "POST",
url: url,
data: params,
success: function(data) {
console.log(func);
mainfunc(func, data);
}
});
}
}
嗨xdazz。非常感谢你这样做。但它不适用于“这个”,我不得不写“myScript”。它找不到 - 不知道;) – user1509034