extends in javascript

复制代码
function extend(subClass,superClass){
    var F = function(){};
    F.prototype = superClass.prototype;
    subClass.prototype = new F();
    subClass.prototype.constructor = subClass;
}


function Person(name){
    this.name = name;
}
Person.prototype.getName = function(){
    return this.name;
}

function Author(name,books){
    Person.call(this,name);
    this.books = books;
}
Author.prototype.getBooks = function(){
    return this.books;
}

extend(Author,Person);


var p = new Person("张三");
var a = new Author("刘畅");

console.log(p.getName());
console.log(a.getName());
相关推荐
神奇的程序员1 天前
开发了一个管理本地开发环境的软件
前端·flutter
天若有情6731 天前
程序员原创|借鉴JS事件冒泡,根治电脑文件混乱的“冒泡整理法”
开发语言·javascript·windows·ecmascript·电脑·办公·日常
XiYang-DING1 天前
HTML 核心标签
前端·html
特种加菲猫1 天前
继承,一场跨越时空的对话
开发语言·c++
Csvn1 天前
技术选型方法论
前端
Csvn1 天前
前端架构演进:从页面到平台的十年变革
前端
李伟_Li慢慢1 天前
ShaderToy-山峦+蓝天+白云
前端·webgl
小码哥_常1 天前
Android字体字重设置全攻略:XML黑科技+Kotlin动态实现,告别.ttf臃肿
前端
FYKJ_20101 天前
springboot校园兼职平台--附源码02041
java·javascript·spring boot·python·eclipse·django·php