functions-delay1
by shan10213223
JavaScript
var _ = {};
// _.delay(function, wait, *arguments)
// Much like setTimeout(), invokes function after waiting milliseconds.
// If you pass the optional arguments, they will be forwarded
// on to the function when it is invoked.
_.delay = function (func, wait) {
//let args = Array.prototype.slice.call(arguments, 2);
let args = arguments[2];
//if (args.length !== 0) {
// console.log(args);
//}
//console.log('start waiting..');
setTimeout(func, wait, args);
};
// tests
//var log = _.bind(console.log, console);
//_.delay(log, 1000, 'logged later');
// => 'logged later' // Appears after one second.
function myshow (w) {
console.log(w);
}
function mydelay (w, t) {
console.log('start waiting..');
setTimeout(myshow, 5000);
}
//mydelay();
_.delay(myshow, 5000, 'hello');