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());
相关推荐
AI人工智能+电脑小能手1 天前
【大白话说Java面试题】【Java基础篇】第9题:HashMap根据key查询元素的时间复杂度是多少
java·开发语言·数据结构·后端·面试·哈希算法·哈希表
霁月的小屋1 天前
不只是压缩:当模型蒸馏开始复制人格
前端·ai
inksci1 天前
使用飞帆的上传组件
前端·javascript
invicinble1 天前
对于java面向对象的知识
java·开发语言
2501_930707781 天前
使用C#代码在 PowerPoint 中创建组合图表
开发语言·c#·powerpoint
里欧跑得慢1 天前
微交互设计模式:提升用户体验的细节之美
前端·css·flutter·web
xiao阿娜的妙妙屋11 天前
做知识视频效率提升10倍!知识博主用什么AI工具做知识视频?我的答案是即梦Seedance 2.0
前端
干洋芋果果1 天前
前端学python
开发语言·前端·python
FOREVER-Q1 天前
基于 Vite 的前端 SDK 工程化设计与模块化构建实践
开发语言·前端·javascript
invicinble1 天前
java面向对象的学习主线
java·开发语言·学习