0

How do I dynamically change the values of this object array

https://code.sololearn.com/WfF2IMexvjKg/?ref=app

10th Aug 2023, 8:43 AM
Indiphile Menziwa
Indiphile Menziwa - avatar
6 ответов
+ 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
10th Aug 2023, 10:34 AM
JaScript
JaScript - avatar
+ 5
How about that: blocks[1].bottomLeft[0] = 50
10th Aug 2023, 11:06 AM
JaScript
JaScript - avatar
+ 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
10th Aug 2023, 11:22 AM
Bob_Li
Bob_Li - avatar
+ 1
And you did it more pro and efficient. OOP that
10th Aug 2023, 2:59 PM
Indiphile Menziwa
Indiphile Menziwa - avatar
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
10th Aug 2023, 10:45 AM
Indiphile Menziwa
Indiphile Menziwa - avatar
0
PHP your hacking please you not white hack we r
11th Aug 2023, 2:43 PM
Toe Htet Shan
Toe Htet Shan - avatar