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
相关推荐
AI人工智能+电脑小能手1 天前
【大白话说Java面试题】【Java基础篇】第9题:HashMap根据key查询元素的时间复杂度是多少霁月的小屋1 天前
不只是压缩:当模型蒸馏开始复制人格inksci1 天前
使用飞帆的上传组件invicinble1 天前
对于java面向对象的知识2501_930707781 天前
使用C#代码在 PowerPoint 中创建组合图表里欧跑得慢1 天前
微交互设计模式:提升用户体验的细节之美xiao阿娜的妙妙屋11 天前
做知识视频效率提升10倍!知识博主用什么AI工具做知识视频?我的答案是即梦Seedance 2.0干洋芋果果1 天前
前端学pythonFOREVER-Q1 天前
基于 Vite 的前端 SDK 工程化设计与模块化构建实践invicinble1 天前
java面向对象的学习主线