【发布时间】:2013-04-18 21:28:10
【问题描述】:
我可以在“非 ajax”函数上使用 jquery done() 吗?当我尝试做这样的事情时,我收到错误Uncaught TypeError: Cannot call method 'done' of undefined。
function countThreeSeconds() {
var counter = 0,
timer = setInterval(function () {
if (counter == 3) {
console.log("All done. That was three seconds.");
window.clearInterval(timer);
} else {
console.log("Not there yet. Counter at: " + counter);
}
counter++;
}, 1000);
}
(function(){
var timer = countThreeSeconds().done(function(){
alert("done");
});
}());
谢谢
【问题讨论】:
-
如您所见,您不能。 jQuery 与它无关。你永远不能在
undefined上调用方法。 jQuery 方法不仅仅神奇地出现在(谢天谢地) 中。您可以在 jQuery 库中定义的特定对象上调用它们,并按照 jQuery 的 API 的描述。
标签: javascript jquery jquery-deferred