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
相关推荐
小村儿3 分钟前
(译文)重温:Karpathy 的 4 条 CLAUDE.md 规则将 Claude 错误率从 41% 降至 11%——历经 30 个代码库后,我又加了 8 条我滴老baby5 分钟前
0基础速通Python+AI|2026热门轻量化玩法全攻略:从入门到实战,3天搞定AI应用开发前端那点事5 分钟前
Vite+Vue3环境判断终极解法!区分开发/生产环境,告别环境报错源码集结号7 分钟前
基于 Spring Boot + JPA + MySQL的上门家政系统代码示例一个天蝎座 白勺 程序猿8 分钟前
Python(29)Python生成器函数深度解析:asyncio事件循环的底层实现与异步编程实战2zcode8 分钟前
原创文档:基于MATLAB的线性预测编码变声器系统七夜zippoe8 分钟前
Python RESTful API设计终极指南:从理论到企业级实战爱喝铁观音的谷力景辉10 分钟前
web端实现音频波形分析以及音频截取lly20240611 分钟前
Highcharts 配置说明车位涂鸦13 分钟前
在线浏览“秀人网合集”的新思路:30 行 Python 把封面图链接秒变本地可点图库