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
相关推荐
Amumu121385 分钟前
CSS简介Yzw18 分钟前
当vue.diff遇上了扩展运算符(...)前端不开发19 分钟前
在任意网页里“召唤”一个火柴人:一次有趣的 JavaScript Hackwhatever who cares27 分钟前
Java Web 架构全组件详解maplewen.32 分钟前
C++11 返回值优化我命由我1234539 分钟前
Android Studio - 在 Android Studio 中直观查看 Git 代码的更改DevDengChao39 分钟前
[Aliyun] [FC] 如何使用 website-fc-serve 插件部署静态网站hewence139 分钟前
Kotlin协程启动方式详解前端拿破轮42 分钟前
利用Github Page + Hexo 搭建专属的个人网站(一)q1cheng1 小时前
基于Spring Boot + Vue项目online_learn的用户登录认证全流程分析