Copy link to clipboard
Copied
Hello friends!
I got a code which was responsible for some drag and drop items. In the code there i saw there was created an array named "positionArray" and two values(X and Y position of an item) are added, you can see in red highlighted area. But i dont't know why word "xPos" and "yPos" are used here in the red highlighted area, and What are they..can anybody please tell me..??
Thank you..
Copy link to clipboard
Copied
The {} notation creates a new Object. "xPos" and "yPos" are simply the identifiers given to properties of that object.
Copy link to clipboard
Copied
What will happen if i remove those highlighted words and only use "dropArray.x, dropArray.y"..??
Copy link to clipboard
Copied
It won't compile...
Copy link to clipboard
Copied
Yep. That'll break it. Objects work by having you assign values to property references - and you are removing those references so it isn't assigning those values to anything. You could do that in the case of an Array - but you should probably stick with how the code was developed and use an Object.
Copy link to clipboard
Copied
Got it..
Thank you guys for your valuable suggestions..
Copy link to clipboard
Copied
Pop04 wrote:
What will happen if i remove those highlighted words and only use "dropArray.x, dropArray.y"..??
In that case it will push both the x value and the y value into the array, as numbers. You'd end up with an array with a bunch of numbers in it -- 2 numbers for every object in dropArray. That could be a way to do it, but the problem is code elsewhere is surely expecting to find objects in the array with xPos and yPos properties, so it would break.
-Aaron
Copy link to clipboard
Copied
you mean every time whenever an object is selected, its x and y postions are stored in that array and so on..Afterall array gets a lot of values as a number in it.