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
相关推荐
San813_LDD28 分钟前
[C语言]《Dev-C++ 报错解决手册(Day0607 精华版)》xiaofeichaichai6 小时前
Webpackfqbqrr7 小时前
2606C++,C++构的多态问心无愧05137 小时前
ctf show web入门111唐某人丶7 小时前
模型越来越强,我们还需要 Agent 工程吗?—— 从价值重估到 Harness 实践智码看视界7 小时前
现代Web开发基础:全栈工程师的起航点biter down7 小时前
从 0 到 1 搭建 Python 接口自动化测试框架(博客系统实战)JS菌7 小时前
手写一个 AI Agent 全栈项目:从沙箱执行到子智能体的完整实现