【发布时间】:2011-09-02 16:54:37
【问题描述】:
我想知道 IF 和 HOW 是否可以编写一个观察其他函数的function。
更准确地说,obsever 跟踪observed 函数执行时间,如果后者超过给定时间值,observer 函数停止它。
所以,简单地说:
function observed() { // ... }
/**
* Run a function and stop if this exceeds a given time.
*
* @param {Function} observedFunc The function to run and observe.
* @param {Number} maxTime The maximum elapsed time allowed.
*/
function observer(observedFunc, maxTime) {
/*
* if (observedFunc exceed the time)
* stop observedFunc;
* return;
* else
* return; (when the observed function return)
*/
}
是否可以在不更改observed 功能的情况下负担得起?
【问题讨论】:
-
我认为不可能在外部停止函数的执行——你必须在你的 observed() 函数中构建超时。
标签: javascript function time