Sunday, 8 September 2013

Where to set self from this, inside a javascript object?

Where to set self from this, inside a javascript object?

I've noticed inside the instance of my object, if I have a jQuery click
handler etc. the this keyword gets overwritten therefore I have to set a
self property outside the scope and access that.
My questions are:
Should I set self, in the body of my object, or in each method. Is there a
difference?
Does self in this case point to the instance and not the class?
Thanks!
var ExampleVM = function () {
var self1 = this;
this.toggleIsSlidedOut = function () {
var self2 = this;
this.$con.animate({
right: '+=' + posX + 'px'
}, 400, function () {
selfx.isSlidedOut(!this.isSlidedOut());
});
};
};

No comments:

Post a Comment