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
相关推荐
小二李5 分钟前
什么是依赖注入(DI)&控制反转IoCCDN3608 分钟前
高防切换后网站打不开?DNS 解析与回源路径故障排查是宇写的啊14 分钟前
SpringIoc和Di沐雪轻挽萤16 分钟前
3. C++17新特性-带初始化的 if 和 switch 语句信也科技布道师19 分钟前
把7个页面变成1段对话:AI如何重构借款流程xianluohuanxiang20 分钟前
2026年深度:高精度气象+新能源,从风速误差到收益偏差,行业赋能正在重构电站盈利模型froginwe1128 分钟前
SQL PRIMARY KEY(主键)2401_8858850431 分钟前
视频短信接口集成起来复杂吗?API接入说明Thexhy33 分钟前
Java 后端完整成长路线(含项目)276695829234 分钟前
携程旅行 token1005