0
How do I dynamically change the values of this object array
6 Antworten
+ 5
There are many ways one of it ie blocks[1] = new Block(50,355). Maybe this help you further:
https://www.w3schools.com/js/js_object_properties.asp
+ 5
How about that:
blocks[1].bottomLeft[0] = 50
+ 1
The way your class Block constructor was set up, the xAxis and yAxis parameters are distributed into four coordinates of the corners.
These coordinates then becomes fixed constants. Changing xAxis or yAxis later on will not affect them.
You would have to change it in four places whenever you change x or y, which is not ideal.
It would have been easier if you just had a reference to xAxis and yAxis in your class. And used class methods to dynamically compute the coordinates of the corners whenever they are accessed.
You need to define those properties dynamically so they will update if you change x or y. One way is to define getters. They are basically class methods, only you don't have to put () at the back, and you use them more like read-only class properties than methods.
also, blockHeight and blockWidth should be numbers, not strings.
https://code.sololearn.com/WHMN037By34k/?ref=app
+ 1
And you did it more pro and efficient. OOP that
0
Yeah but all these objects have keys, is there a way to change only one value of the object without the one on your example. To only extract the "50" alone then change it
0
PHP your hacking please you not white hack we r