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