please help...how to create a link to "this" in anoymous function?
if i do so..."that" in each instance of ClassA is always the last instance. I understand why it doesn't work...but it just interesting..is it possible to create somehow this secret link or not?HTML Code:(function() { function OnClick() { console.log(that.id); } ClassA = function(id) { this.id = id; this.element = document.getElementById(id); this.element.onclick = OnClick; // secret link that = this; } })(); for(var i...) { var x = new ClassA("element_" + id); }
I have tryed so:
and so...HTML Code:that = function (t) { return t; }(this);
nothing works...is it possible?HTML Code:GetThis = function (t) { return function () { return t }; }(this);




Bookmarks