I can't get how to access that value, this is my code:
function Filters()
{
this.filters = ["filter_1", "filter_2", "filter_3"];
this.someData = "test";
this.draw = draw;
function draw(){
for(var i=0; i<this.filters.length;i++)
{
var filter = this.filters[i];
$("#" + filter).click(function(){
doSomething();
});
}
}
function doSomething(){
alert(this.someData);
}
}
I am aware of the fact that since doSomething() is called from within the closure, this. will refer a JQuery object being worked on. So how do I go about being able to use someData from my object in that function/closure ? Can't seem to figure it out.
Thanks for help :)
.click(doSomething). Currently it's nothing (or the global object).Filters()is a constructor, written to be called withnew Filters(). As written the constructor will behave very differently if called withoutnew. To understand the issues here, and to learn how to write constructors that are tolerant of a missingnew, try this, by John Resig. It's fairly heavyweight stuff but worth persisting with.