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