. entry. , . , , , . . .
function addClickHandlers() {
var entries = [{id: 1},{id: 2},{id: 3}];
var i = entries.length;
while (i--) {
var entry = entries[i];
document.getElementById(entry.id).onclick = getClickHandler(entry);
}
}
function getClickHandler(entry) {
return function() {
console.log("this.id: " + this.id);
console.log("entry.id: " + entry.id);
};
}
. for , javascript, , , .
, . , .
Ext createDelegate
myhandler.createDelegate(scope, [arguments], [appendArgs]);
javascript 1.8.5 .prototype.bind
myhandler.bind(scope, arguments)
.prototype.bind ( )
Function.prototype.bind = function(self, var_args) {
var thisFunc = this;
var leftArgs = Array.slice(arguments, 1);
return function(var_args) {
var args = leftArgs.concat(Array.slice(arguments, 0));
return thisFunc.apply(self, args);
};
};
source
share