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
相关推荐
人道领域几秒前
【黑马点评日记】社交平台用户关注功能全解析Feed流相关操作xiaoshuaishuai822 分钟前
C# DeepSeek V4 与 V3对比vivo互联网技术25 分钟前
下一代图片格式 AVIF 在 vivo 社区的落地实践咸鱼翻身更入味28 分钟前
Vue创建一个简单的Agent聊天bluetata28 分钟前
AI 浪潮与破局:TypeScript 生态实战,让 AI 为你所用shehuiyuelaiyuehao30 分钟前
算法18,二分查找IT策士33 分钟前
Python mcp研究:入门到精通布局呆星34 分钟前
Vue Router 核心知识点梳理罗技12335 分钟前
告别“兼容模式“:Easysearch 有了自己的官方 Python 客户端