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?
4 ответов
+ 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 ^^
+ 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'...
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?
0
thanks.