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
相关推荐
HashTang3 分钟前
我用 Cloudflare Workers + GitHub Actions 做了个 2.5 刀/月的 AI 日报,代码开源了老王以为10 分钟前
前端重生之 - 前端视角下的 Python2601_9491942613 分钟前
Python爬虫完整代码拿走不谢饭后一颗花生米20 分钟前
2026 AI加持下前端学习路线:从入门到进阶,高效突破核心竞争力五号厂房22 分钟前
TypeScript 类型导入详解:import type 与 import {type}c***892031 分钟前
python爬虫——爬取全年天气数据并做可视化分析果然_34 分钟前
为什么你的 PR 总是多出一堆奇怪的 commit?90% 的人都踩过这个 Git 坑xpyjs38 分钟前
零依赖、链式调用、可变对象:重新设计 JavaScript 颜色处理体验WayneYang40 分钟前
Node.js 全栈知识点详细整理(含代码示例 + 前端结合实战)土拨鼠爱coding42 分钟前
Chrome插件 - DIY Theme