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());
相关推荐
一只小阿乐2 分钟前
react路由中使用context
前端·javascript·react.js·context 上下文
Hilaku3 分钟前
一周狂揽40K+ Star⭐ 的 Pretext 到底有多变态?
前端·javascript·html
前端郭德纲3 分钟前
JavaScript 原型相关属性详解
开发语言·javascript·原型模式
533_4 分钟前
适用于vue3的拖拽插件:vue-draggable-plus, vuedraggable@next
javascript·vue.js
Southern Wind5 分钟前
AI Skill Server 动态技能中台
前端·后端·mysql·node.js
于先生吖7 分钟前
基于 SpringBoot 架构,高性能 JAVA 动漫短剧系统源码
java·开发语言·spring boot
无限进步_13 分钟前
【C++&string】寻找字符串中第一个唯一字符:两种经典解法详解
开发语言·c++·git·算法·github·哈希算法·visual studio
锦木烁光27 分钟前
多端项目太乱?我是这样用 Monorepo 重构的
前端·架构
早點睡39027 分钟前
ReactNative项目OpenHarmony三方库集成实战:react-native-shadow-2
javascript·react native·react.js
上山打牛31 分钟前
cornerstone3D基本使用
前端