I am very new to javascript prototypes. So I am wondering If the following is legal and will always work :
function Obj(name) {
this.name = name;
}
Obj.prototype.getName() {
return this.name;
}
and then :
var obj1 = new Obj("one");
var obj2 = new Obj("two");
alert(obj1.getName() + " " + obj2.getName());
Will I get “one two”. I know this is a simple example, but will things like this always reference object instances or will this mean the prototype or an event. Thanks
1 Answer