父类
function Person(name) {
this.name = name;
}
Person.prototype.getName = function() {
return this.name;
}function extend(subClass, superClass) {
var F = function() {};
F.prototype = superClass.prototype;
subClass.prototype = new F();
subClass.prototype.constructor = subClass;
subClass.superclass = superClass.prototype;
if(superClass.prototype.constructor == Object.prototype.constructor) {
superClass.prototype.constructor = superClass;
}
}
function Author(name, books) {
Author.superclass.constructor.call(this, name);
this.books = 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(‘, ‘);
};js面向对象编程,一个完整的继承例子,布布扣,bubuko.com
原文:http://blog.csdn.net/xuexiaodong009/article/details/21095145