/* class Person */
function Person(name) {
this.name = name;
}
Person.prototype.getName = functino() {
return this.name;
}
var reader = new Person('brainzhang');
reader.getName();
好,下面定义一个它的子类
12345678
/* Class Author */
function Author(name, books) {
Person.call(this, name);
this.books = books;
}
Author.prototype = new Persion(); //set up the prototype chain
Author.prototype.contructor = Author; //set the constructor attribute to author
Author.getBooks = function() {return this.books;}
容易费解的是这两行:
12
Author.prototype = new Persion(); //set up the prototype chain
Author.prototype.contructor = Author; //set the constructor attribute to author
function extend(subClass, superClass) {
var F = function(){};
F.prototype = superClass.prototype;
subClass.prototype = new F();
subClass.prototype.contructor = subClass;
}