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
相关推荐
xieliyu.6 小时前
Java算法精讲:双指针(二)云水一下6 小时前
TypeScript 从零基础到精通(五):高级类型与泛型何以解忧,唯有..6 小时前
Python包管理工具pip:从入门到精通counterxing6 小时前
vibe coding 之后,我更不想打字了雪的季节7 小时前
RabbitMQ详解云水一下7 小时前
TypeScript 从零基础到精通(六):类型声明与模块化copyer_xyf7 小时前
Python 模块与包的导入导出研☆香7 小时前
es6新特性功能介绍(四)微扬嘴角7 小时前
React篇1--JSX语法规则、组件、组件实例的3大特性ice8130331817 小时前
【Python】Matplotlib折线图绘制