0
(Got it) need a real life example/source for JavaScript Object.. For understand how can we use object in project if we need.
8 Antworten
+ 3
var first_box = {
x : 0, y: 5 ,size: 5 }
var second_box = {
x : 0, y: 15 ,size: 5 }
box(first_box.x ,first_box.y,first_box.size)
And same with second also and you can notice it is easy for you to understand then which is defined to which and it's very hard to name var like x1 ,x2 ,x3 etc. So it is helpful for understanding .
Thank you!
All the best!
+ 2
NOTE - https://www.sololearn.com/Discuss/333866/?ref=app
An object is a collection of properties, and a property is an association between a name (or key) and a value. A property's value can be a function, in which case the property is known as a method. In addition to objects that are predefined in the browser, you can define your own objects.
Eg -
Suppose we are making a animation in which there are two boxes and we want to move those boxes left to right.
Suppose there is a function whose name is box() which take argument as x, y and size .
So we will write like this,
var x1 = 0
var x2 = 0
var y1 = 5
var y2 = 15
var size = 5
box(x1, y1, size)
box(x2,y2,size)
Two boxes created now for moving it we need to increase x-axis ,so we will write x1 += 1 and x2 += 1 and our box will start moving. But this is not the right way I think. It will be more easy to recognize for you by creating object.
+ 2
Thank you :)
+ 1
❣ Thanks bro.. now we have idea how i will use object method in javascript!
+ 1
Martin Taylor i already two times revised javascript toutrial from sololearn
+ 1
But problme is that i did not created any long project with javascript