Recently delving into OOP in JavaScript while working on an AngularJS website, I encountered a situation where my object methods were only altering the properties within the class, but not affecting the new object itself.
//Class
Var Item = function() {
this.currentItem = 1;
}
Item.prototype.itemUp = function(){
this.currentItem++;
}
//New Object
item = new Item();
$scope.currentItem = item.currentItem;
item.itemUp();
Upon some debugging, I discovered that the code was updating the `Item.currentItem`, rather than `item.currentItem` as desired.
console.log(item.currentItem) --> 1
console.log(Item.currentItem) --> 2
I am seeking guidance on how to ensure that the class method modifies the newly created object, and not the class itself. Any advice would be greatly appreciated!
Thank you,