当前位置:网站首页>TypeScript–es5中的类,继承,静态方法
TypeScript–es5中的类,继承,静态方法
2022-06-30 09:50:00 【全栈程序员站长】
最简单的类
function Person() {
this.name = 'lisi';
this.age = 20;
}
var p = new Person();
alert(p.name);构造函数和原型链里增加方法
function Person() {
this.name = 'lisi';
this.age = 20;
this.run = function() {
alert(this.name + '在运动');
}
}
Person.prototype.sex = '男';
Person.prototype.work = function() {
alert(this.name + '在工作');
}
var p = new Person();
alert(p.name);
p.run();
p.work()类里的静态方法
function Person() {
this.name = 'lisi';
this.age = 20;
this.run = function() {
alert(this.name + '在运动');
}
}
Person.getInfo = function() {
alert('我是静态方法')
}
Person.prototype.sex = '男';
Person.prototype.work = function() {
alert(this.name + '在工作');
}
var p = new Person();
// p.work();
Person.getInfo()es5里面的继承,对象冒充实现继承
只有一个弹框,说明没有继承到prototype上的方法
function Person() {
this.name = 'lisi';
this.age = 20;
this.run = function() {
alert(this.name + '在运动');
}
}
Person.prototype.sex = '男';
Person.prototype.work = function() {
alert(this.name + '在工作');
}
//Web类继承Person类
function Web() {
Person.call(this);
}
var w = new Web();
w.run();
w.work();es5里面的继承,原型链实现继承
function Person() {
this.name = 'lisi';
this.age = 20;
this.run = function() {
alert(this.name + '在运动');
}
}
Person.prototype.sex = '男';
Person.prototype.work = function() {
alert(this.name + '在工作');
}
//Web类继承Person类
function Web() {
}
Web.prototype = new Person();
var w = new Web();
w.run();
w.work();原型链实现继承的问题
function Person(name, age) {
this.name = name;
this.age = age;
this.run = function() {
alert(this.name + '在运动');
}
}
Person.prototype.sex = '男';
Person.prototype.work = function() {
alert(this.name + '在工作');
}
function Web(name, age) {
}
Web.prototype = new Person();
var w = new Web('lisi', 20)
w.run()
w.work()原型链+对象冒充的组合继承模式
function Person(name, age) {
this.name = name;
this.age = age;
this.run = function() {
alert(this.name + '在运动');
}
}
Person.prototype.sex = '男';
Person.prototype.work = function() {
alert(this.name + '在工作');
}
function Web(name, age) {
Person.call(this, name, age);
}
Web.prototype = new Person();
var w = new Web('lisi', 20)
w.run()
w.work()原型链+对象冒充的另一种方式
function Person(name, age) {
this.name = name;
this.age = age;
this.run = function() {
alert(this.name + '在运动');
}
}
Person.prototype.sex = '男';
Person.prototype.work = function() {
alert(this.name + '在工作');
}
function Web(name, age) {
Person.call(this, name, age);
}
Web.prototype = Person.prototype;
var w = new Web('lisi', 20)
w.run()
w.work()发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/101123.html原文链接:https://javaforall.cn
边栏推荐
- Oracle creates a stored procedure successfully, but the compilation fails
- Implementation of monitor program with assembly language
- Node environment configuration
- 著名画家史国良《丰收时节》数字藏品上线长城数艺
- Musk has more than 100 million twitter fans, but he has been lost online for a week
- Great Wall digital art digital collection platform releases the creation Badge
- 透过华为军团看科技之变(五):智慧园区
- "Kunming City coffee map" was opened again, and coffee brought the city closer
- L'activité "Kunming City coffee map" a rouvert
- ArcGIS Pro scripting tool (5) - delete duplicates after sorting
猜你喜欢

Yixian e-commerce released its first quarterly report: adhere to R & D and brand investment to achieve sustainable and high-quality development

MySQL advanced SQL statement of database (2)

马斯克推特粉丝过亿了,但他在线失联已一周

6. Redis new data type

KOREANO ESSENTIAL打造气质职场范

How to seize the opportunity of NFT's "chaos"?

L'activité "Kunming City coffee map" a rouvert

ArcGIS Pro scripting tool (6) -- repairing CAD layer data sources

mysql数据库基础:视图、变量

ArcGIS Pro脚本工具(5)——排序后删除重复项
随机推荐
Highlight display of Jinbei LB box, adhering to mini special effects
Skill sorting [email protected]+ Alibaba cloud +nbiot+dht11+bh1750+ soil moisture sensor +oled
“昆明城市咖啡地图”活动再度开启
CVPR 2022 | 清华&字节&京东提出BrT:用于视觉和点云3D目标检测的桥接Transformer
光明行动:共同呵护好孩子的眼睛——广西实施光明行动实地考察调研综述
最新SCI影响因子公布:国产期刊最高破46分!网友:算是把IF玩明白了
Getting started with X86 - take over bare metal control
Xinguan has no lover, and all the people benefit from loving deeds to warm the world -- donation to the public welfare action of Shangqiu children's welfare home
Robot system dynamics - inertia parameters
CVPR 2022 | Tsinghua & bytek & JD put forward BRT: Bridging Transformer for vision and point cloud 3D target detection
MySQL index, transaction and storage engine of database (2)
【Rust每周一库】num-bigint - 大整数
Skill combing [email protected] voice module +stm32+nfc
WGet -- 404 not found due to spaces in URL
MySQL advanced SQL statement of database (1)
GD32 RT-Thread flash驱动函数
SGD有多种改进的形式,为什么大多数论文中仍然用SGD?
train_ de.py: error: argument --save_ steps: invalid int value: ‘$[$[889580/128/4]*10/2]‘
The preliminary round of the sixth season of 2022 perfect children's model Hefei competition area was successfully concluded
Notes on numerical calculation - iterative solution of linear equations