What is the proper way to create a function that updates an object's fields? The way below, nothing seems to happen:
function adjmatrix(neighbors){
this.neighbors = neighbors
this.sum = 0
}
adjmatrix.prototype.update = function(){
this.neighbors.forEach(function(a){a.sum += 10})
}
var myMatrix = new adjmatrix([1,2,3])
myMatrix.update()
print(myMatrix.sum) //Expect a value of 30, I get 0.
Kind of new to Javascript, so I'm not too clear on how scoping and stuff works. Thanks for your help. I am running my programming through d8
in the command line.