javascript - Calling onclick with local variable -
javascript - Calling onclick with local variable -
first, apologies asking must answered here somewhere (i've been looking!)
i want this:
var i; (i = 0; < 5; i++) { ... // add together anchor dom ... a.onclick = goog.bind(this.dosomething, this); ... } namespace.clazz.prototype.dosomething = function(event, index) { console.log('index: ' + index); } i want 5 anchors each pass different value i dosomething when clicked (along click event). want maintain context of this in dosomething (hence bind).
if can reverse order arguments received, should able this...
a.onclick = goog.bind(this.dosomething, this, i); so dosomething should this...
namespace.clazz.prototype.dosomething = function(index, event) { console.log('index: ' + index); }; at to the lowest degree that's how looks the google closure library source.
javascript google-closure
Comments
Post a Comment