Skip to content

Instantly share code, notes, and snippets.

@s-hiroshi
Created April 21, 2012 11:57
Show Gist options
  • Save s-hiroshi/2436777 to your computer and use it in GitHub Desktop.
Save s-hiroshi/2436777 to your computer and use it in GitHub Desktop.
JavaScript > pattern > setTimeout
/**
* Custom function can pass arguments(string, number, object, array, function) to a function.
*/
/**
* 参考サイト
* WIZARD-CODE ウィザード・コードのブログ | WIZ-CODE.blog
* http://wiz-code.digick.jp/blog/?p=711
*/
function customTimeout() {
var func = arguments[0],
args = Array.prototype.slice.call(arguments, 1);
return function() {
return func.apply(this, args);
};
}
var o = {
x: 100,
y: 200
}
function print(arg) {
console.log(arg);
}
setTimeout(customTimeout(print, o), 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment