本文介绍了为什么Underscore.js有延迟功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是Underscore.js的源代码'延迟
功能:
This is the source code for Underscore.js' delay
function:
_.delay = function (func, wait) {
var args = slice.call(arguments, 2);
return setTimeout(function () { return func.apply(null, args); }, wait);
};
这与 setTimeout
有什么不同?为什么Underscore.js需要延迟
?
How is this any different from setTimeout
? Why does Underscore.js need delay
?
推荐答案
这是一个跨浏览器能够传递额外参数的方法,这些参数将作为回调的参数出现,如 setTimeout()
。这在IE中不起作用。
It's a cross browser way of being able to pass extra arguments which will appear as the arguments to the callback, like setTimeout()
. This doesn't work in IE.
它可以使你的代码更漂亮......
It can make your code prettier...
setTimeout(_.bind(function() { }, null, "arg1"), 1e3);
... vs ...
...vs...
_.delay(function() { }, 1e3, "arg1");
我同意它是一种不太有用的Underscore方法,在。
I agree that it's one of the less useful Underscore methods, which are outlined in Naomi's answer.
这篇关于为什么Underscore.js有延迟功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!