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());
相关推荐
平凡但不平庸的码农3 分钟前
Go 错误处理详解
开发语言·后端·golang
小陈的进阶之路4 分钟前
Python系列课(2)——判断
java·前端·python
2301_8156453810 分钟前
html.
前端·html
z2005093016 分钟前
C++中位图和布隆过滤器的一些面试题
开发语言·c++
Bat U35 分钟前
JavaEE|文件操作和IO
java·开发语言
qq_3813385038 分钟前
CSS @layer 级联层实战指南:从样式冲突到分层架构
前端·css
广州华水科技41 分钟前
深度测评2026年好用的单北斗GNSS变形监测系统推荐,提升GNSS位移监测精度,引领智能监控新风尚
前端
脉动数据行情41 分钟前
Python 实现融通金行情数据对接(实时推送 + K 线 + 产品列表)
开发语言·python
花归去1 小时前
vue3中 function getText(){} 、 const getText=()=>{} ;区别在哪里,优缺点
javascript·vue.js·ecmascript
ZC跨境爬虫1 小时前
跟着 MDN 学 HTML day_33:(Attr 接口与属性节点的深入理解)
前端·javascript·ui·html·音视频·html5