0

How do you reference the values of every instant of an object u create?

if you use a constructir function to later create objects from that prototype...how do youreference those values from each object?

8th Jan 2017, 8:23 AM
Carlito
4 Respuestas
+ 4
The class-like declaration in JS, is like: MyClass = function(params) { this.my_var = params; } So you instanciate with: p = "argument item"; my_instance = new MyClass(p); The reference is stored in the variable named 'p'... You access to it's properties/methods with the dot notation: document.write(p.my_var); So, for stored many instance, you need many variables... and for handle that, it's usefull to organize them in structure like arrays ^^
8th Jan 2017, 8:32 AM
visph
visph - avatar
+ 3
You mean 'access' when you say 'reference' then ;) document.write(kobe.name); document.write(kobe.points); document.write(kobe.dob); And so on with 'shaq'...
8th Jan 2017, 8:47 AM
visph
visph - avatar
0
I am trying to really understand your answer but am a bit confuse with your example. function Lakers(name, points, dob){ this.name= name; this.points=points; this.dob=dob}; var kobe = new Lakers("kobe bryant", 25, "june 8"); var shaq = new Lakers("shaq oneal",24, "july 4"); in this example, how would I reference say shaqs points? and how can I organize say 20 players (instance of objects) so I can access them in the future?
8th Jan 2017, 8:44 AM
Carlito
0
thanks.
8th Jan 2017, 8:51 AM
Carlito