/* Extend Function */
function extend(subClass,superClass){
var Func = function(){} ;
Func.prototype = superClass.prototype ;
subClass.prototype = new Func() ;
subClass.prototype.constructor = subClass ;
} ;
/*-----Example-----*/
/* Class Person */
function Person(name){
this.name = name ;
} ;
Person.prototype.getName = function(){
return this.name ;
} ;
/* Class Author */
function Author(name,books){
Person.call(this,name) ;
this.books = books ;
} ;
extend(Author,Person) ;
Author.prototype.getBooks = function(){
return this.books ;
} ;
JavaScript实现继承---extend函数
最新推荐文章于 2021-10-08 09:51:59 发布
1052

被折叠的 条评论
为什么被折叠?



