first batch of documentation

This commit is contained in:
Jeremy Ashkenas
2009-10-26 16:07:09 -04:00
parent 42362a2742
commit 4c41af41e6
4 changed files with 351 additions and 1 deletions

View File

@@ -283,6 +283,29 @@ window._ = {
});
},
// Delays a function for the given number of milliseconds, and then calls
// it with the arguments supplied.
delay : function(func, wait) {
var args = _.toArray(arguments).slice(2);
return window.setTimeout(function(){ return func.apply(func, args); }, wait);
},
// Defers a function, scheduling it to run after the current call stack has
// cleared.
defer : function(func) {
return _.delay.apply(_, [func, 1].concat(_.toArray(arguments).slice(1)));
},
// Returns the first function passed as an argument to the second,
// allowing you to adjust arguments, run code before and after, and
// conditionally execute the original function.
wrap : function(func, wrapper) {
return function() {
var args = [func].concat(_.toArray(arguments));
return wrapper.apply(wrapper, args);
};
},
/* ---------------- The following methods apply to objects ---------------- */
// Retrieve the names of an object's properties.