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
相关推荐
kyriewen1 天前
2026 年了,还在用 Node.js?Bun 迁移实战:20 分钟搞定,附踩坑记录青山Coding1 天前
Cesium应用(八):物体运动的实现思路用户41659673693551 天前
Android WebView 加载 file:// 离线页面调试教程Asmewill1 天前
curl命令学习笔记一我是一只快乐的小螃蟹1 天前
1.2 ArrayList 源码解析星栈1 天前
我用 Rust + Dioxus 做了个全栈跨平台笔记应用:再把新建、编辑和交付补上我是一只快乐的小螃蟹1 天前
1.1 HashMap (JDK1.8) 源码解析爱勇宝1 天前
小红花成长新版:模板来了,鼓励也更容易开始竹林8181 天前
Solana前端开发:我在一个NFT铸造页面上被@solana/web3.js的Connection和Transaction签名坑了两天冬奇Lab1 天前
每日一个开源项目(第144篇):ai-website-cloner-template - 一条命令、多 Agent 并行,把任意网站逆向成 Next.js 代码