日期:2014-05-16 浏览次数:20375 次
function clone(object){
    function F(){}
    F.prototype = object;
    return new F();
}
var Person = {
    name : "maoyuanjun",
    getName : function(){
        return this.name;
    }
}
var Author = clone(Person);
Author.books = [];
/*
[color=#FF0000]//这样子声明是错误的
Author.prototype.getBooks = function(){
    return this.books;
}
*/[/color]
[color=#FF0000]//这样子声明是正确的呢?
Author.getBooks = function(){
    return this.books;
}[/color]
var author = [];
author[0] = clone(Author);
author[0].name = "myj";
author[0].books = ["java"];
author[1] = clone(Author);
author[1].name = "zlp";
author[1].books = ["javascript"];
alert(author[0].getName() + "," + author[0].getBooks());
alert(author[1].getName() + "," + author[1].getBooks());
Author.prototype.getBooks = function(){
    return this.books;
}