function extend(subClass, superClass){
var F = function(){};
F.prototype = superClass.prototype;
subClass.prototype = new F();
subClass.prototype.contructor = subClass;
subClass.superclass = superClass.prototype;
if(superClass.prototype.constructor == Object.prototype.constructor){
superClass.prototype.constructor = superClass;
}
}
function Person(name){
this.name = name;
}
Person.prototype.getName = function(){
return "sss";
}
function Author(name, books){
Author.superclass.constructor.call(this, name);
this.books = [];
}
extend(Author, Person);
Author.prototype.getBooks = function(){
return this.books;
}
Author.prototype.getName = function(){
var name = Author.superclass.getName.call(this);
return name + ", Author of" + this.getBooks().join(",");
}
window.onload = function(){
//var a = new Author("li","abcdefg");
alert(Author.superclass.getName());
}
有了superclass属性就可以直接调用超类中的方法。这在既要重定义超类的某个方法而又想访问其在超类中的实现时可以派上用场。