according to 1, When we calling the increment method. a is increasing with the given parameter to the function, if no parameter passed then it is inc by 1.
But according to 2, when i write the code like below, a is not inc, always 1 only. Why??.... Please solve this....
// 1
var Obj1 = {
a: 0,
increment: function(inc) {
this.a += typeof inc === 'number' ? inc : 1;
}
};
// 2
var Obj1 = {
a: 0,
increment: function(inc) {
this.value = this.a + typeof inc === 'number' ? inc : 1;
}
};