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

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -