2011-07-19 36 views
0

我想延迟准备好的方法调用(准备好=所有参数已经设置)以供执行。例如:准备要执行的方法调用

我有以下监听方法的文本框:

var storedRequest = null; 
function doAjaxRequest() { 
    //if there is no request at this moment, do the request 
    //otherwise: store the request and do nothing 

} 
//will be executed after a request is done 
function callbackAjaxRequestComplete() { 
    //is storedRequest != null --> Execute that request (the last one) 
} 

那么,有没有存放一个PREPARED方法调用执行成为了可能?

回答

3

你可以做这样的事情:

var preparedOperation = function() { 
    return actualOperation(param1, param2, param3); 
}; 

然后随时调用“preparedOperation”将是您的实际函数的调用。

Functional.js这个库有一些有趣的支持代码。

+0

到Functional.js另一种方法是[underscore.js](http://documentcloud.github.com/underscore/) – Raynos