You have a problem because thisin method1()is different from thisin an external function. This is because a scope is created in JS functions.
First approach
So you may want to abe a variable, not a property this:
createObject = function() {
var a = 1
this.method1 = function() {
if (a == 1 ) {
a = 0
}
}
}
Second approach
this ( self ):
createObject = function() {
var self = this;
this.a = 1
this.method1 = function() {
if (self.a == 1 ) {
self.a = 0
}
}
}
, bind() this method1():
var createObject = function () {
this.a = 1
this.method1 = function () {
console.log(this.a);
if (this.a == 1) {
this.a = 0
}
}.bind(this);
}
bind(). , IE < 9.