/* 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函数
最新推荐文章于 2020-11-16 14:58:27 发布