HTML and CSS Reference
In-Depth Information
rather than a simple link to the prototype. Calling the method should magically
call the corresponding method on the prototype chain. The concept is illustrated in
Listing 7.36.
Listing 7.36 Testing the _ super method
"test super should call method of same name on protoype":
function () {
function Person(name) {
this.name = name;
}
Person.prototype = {
constructor: Person,
getName: function () {
return this.name;
},
speak: function () {
return "Hello";
}
};
function LoudPerson(name) {
Person.call(this, name);
}
LoudPerson.inherit2(Person, {
getName: function () {
return this._super().toUpperCase();
},
speak: function () {
return this._super() + "!!!";
}
});
var np = new LoudPerson("Chris");
assertEquals("CHRIS", np.getName());
assertEquals("Hello!!!", np.speak());
}
In this example we are using Function.prototype.inherit2 to estab-
lish the prototype chain for the LoudPerson objects. It accepts a second argument,
 
Search WWH ::




Custom Search