Why does Underscore.js have a delay function?
Because dumb. This particular underscore.js method seems pretty stupid.
Cons
- additional function in lib means larger code base
- larger code base means more to maintain and more possible bugs
- code that uses this function now has a dependency on that lib
- lesser/nil improvement over native API means low cost:gain ratio
- new apis to learn
Pros
this section intentionally left blank
I would just learn to use javascript and do something like
var hello = function() {
console.log("hello");
};
var delay = 1000;
window.setTimeout(hello, delay);
Simple, right? Underscore.js is sometimes pretty useless. Honestly, window.setTimeout
is perfectly useful just the way it is.
Here's another example to show how to pass an arg to the function
var Cat = function(name) {
function meow(message) {
console.log(name, "says meow!", message);
}
this.meow = meow;
};
var duchess = new Cat("Duchess");
window.setTimeout(duchess.meow.bind(duchess, "please feed me!"), 2000);
// 2 seconds later
// => Duchess says meow! please feed me!
If you can't depend on .bind
you can use a closure too
window.setTimeout(function() {
duchess.meow("please feed me!");
}, 1000);
Wow, that was difficult, though. I'm going back to underscore and lodash and jquery. This JavaScript stuff is tough !