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 小时前
Rust实战七 |基于带 colored 颜色文字控制台的批量文件删除工具夜焱辰6 小时前
浏览器端 Agent 的文件版本管理:不用 Git,基于 OPFS + SQLite 自己造了一个梦想的颜色6 小时前
TypeScript 完全指南(下):从类型体操到生产级配置比昨天多敲两行6 小时前
linux 线程概念与控制huaweichenai6 小时前
php 根据每个类型的抽签范围实现抽签功能Hi~晴天大圣7 小时前
npm使用介绍codeejun8 小时前
每日一Go-73、云原生成本优化 —— 资源限制 & 指标驱动扩容888CC++8 小时前
如何在 C 语言中进行程序调试?就叫_这个吧8 小时前
Java注解、元注解、自定义注解定义及应用喵个咪8 小时前
基于 Taro 的 Headless CMS 多端前端架构:技术解析与二次开发导引