Core > setTimeout
Patterns: setTimeoutのコールバックへ引数を渡すパターン (1) カリー化
by s_hiroshi
JavaScript
function curryTimerCallback() {
var userFunc = arguments[0],
args = Array.prototype.slice.call(arguments, 1);
return function() {
return userFunc.apply(this, args);
};
}
var o2 = {
x: 'property',
callback4: function(arg) {
console.log('x: ' + arg.x);
},
run2: function() {
setTimeout(curryTimerCallback(this.callback4, this), 2500);
}
};
o2.run2(); // xはproperty