Created
April 21, 2012 11:57
-
-
Save s-hiroshi/2436777 to your computer and use it in GitHub Desktop.
JavaScript > pattern > setTimeout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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