当前位置:网站首页>Typescript – classes in Es5, inheritance, static methods
Typescript – classes in Es5, inheritance, static methods
2022-06-30 10:39:00 【Full stack programmer webmaster】
The simplest class
function Person() {
this.name = 'lisi';
this.age = 20;
}
var p = new Person();
alert(p.name);
Add method to constructor and prototype chain
function Person() {
this.name = 'lisi';
this.age = 20;
this.run = function() {
alert(this.name + ' In sports ');
}
}
Person.prototype.sex = ' male ';
Person.prototype.work = function() {
alert(this.name + ' at work ');
}
var p = new Person();
alert(p.name);
p.run();
p.work()
Static methods in class
function Person() {
this.name = 'lisi';
this.age = 20;
this.run = function() {
alert(this.name + ' In sports ');
}
}
Person.getInfo = function() {
alert(' I'm a static method ')
}
Person.prototype.sex = ' male ';
Person.prototype.work = function() {
alert(this.name + ' at work ');
}
var p = new Person();
// p.work();
Person.getInfo()
es5 The inheritance inside , Object impersonates to implement inheritance
Only one bullet box , Description does not inherit to prototype The method on the
function Person() {
this.name = 'lisi';
this.age = 20;
this.run = function() {
alert(this.name + ' In sports ');
}
}
Person.prototype.sex = ' male ';
Person.prototype.work = function() {
alert(this.name + ' at work ');
}
//Web Class inheritance Person class
function Web() {
Person.call(this);
}
var w = new Web();
w.run();
w.work();
es5 The inheritance inside , Prototype chain implementation inheritance
function Person() {
this.name = 'lisi';
this.age = 20;
this.run = function() {
alert(this.name + ' In sports ');
}
}
Person.prototype.sex = ' male ';
Person.prototype.work = function() {
alert(this.name + ' at work ');
}
//Web Class inheritance Person class
function Web() {
}
Web.prototype = new Person();
var w = new Web();
w.run();
w.work();
The problem of prototype chain implementation inheritance
function Person(name, age) {
this.name = name;
this.age = age;
this.run = function() {
alert(this.name + ' In sports ');
}
}
Person.prototype.sex = ' male ';
Person.prototype.work = function() {
alert(this.name + ' at work ');
}
function Web(name, age) {
}
Web.prototype = new Person();
var w = new Web('lisi', 20)
w.run()
w.work()
Prototype chain + Composite inheritance pattern of object impersonation
function Person(name, age) {
this.name = name;
this.age = age;
this.run = function() {
alert(this.name + ' In sports ');
}
}
Person.prototype.sex = ' male ';
Person.prototype.work = function() {
alert(this.name + ' at work ');
}
function Web(name, age) {
Person.call(this, name, age);
}
Web.prototype = new Person();
var w = new Web('lisi', 20)
w.run()
w.work()
Prototype chain + Another way to impersonate objects
function Person(name, age) {
this.name = name;
this.age = age;
this.run = function() {
alert(this.name + ' In sports ');
}
}
Person.prototype.sex = ' male ';
Person.prototype.work = function() {
alert(this.name + ' at work ');
}
function Web(name, age) {
Person.call(this, name, age);
}
Web.prototype = Person.prototype;
var w = new Web('lisi', 20)
w.run()
w.work()
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/101123.html Link to the original text :https://javaforall.cn
边栏推荐
- 滴滴开源敏捷测试用例管理平台!
- Skill combing [email protected] somatosensory manipulator
- MySQL advanced SQL statement of database (2)
- 我的远程办公深度体验 | 社区征文
- 马斯克推特粉丝过亿了,但他在线失联已一周
- Robotframework learning notes: environment installation and robotframework browser plug-in installation
- 今晚19:00知识赋能第2期直播丨OpenHarmony智能家居项目之控制面板界面设计
- Highlight display of Jinbei LB box, adhering to mini special effects
- How to seize the opportunity of NFT's "chaos"?
- 逸仙电商发布一季报:坚持研发及品牌投入,实现可持续高质量发展
猜你喜欢
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
ArcGIS Pro scripting tool (6) -- repairing CAD layer data sources
机器学习面试准备(一)KNN
[email protected] voice module +stm32+nfc"/>
Skill combing [email protected] voice module +stm32+nfc
RobotFramework学习笔记:环境安装以及robotframework-browser插件的安装
mysql数据库基础:存储过程和函数
[email protected] control a dog's running on OLED"/>
Skill combing [email protected] control a dog's running on OLED
MySQL index, transaction and storage engine of database (2)
CSDN博客运营团队2022年H1总结
Guolin was crowned the third place of global popularity of perfect master in the third quarter of 2022
随机推荐
Migrate full RT thread to gd32f4xx (detailed)
The famous painter shiguoliang's "harvest season" digital collection was launched on the Great Wall Digital Art
【Rust每周一库】num-bigint - 大整数
Skill combing [email protected] intelligent instrument teaching aids based on 51 series single chip microcomputer
Launch of Rural Revitalization public welfare fund and release of public welfare bank for intangible cultural heritage protection of ancient tea tree
RobotFramework学习笔记:环境安装以及robotframework-browser插件的安装
WGet -- 404 not found due to spaces in URL
Chen Haotian won the national championship of the national finals of the 7th children's model star ceremony
Apple's 5g chip was revealed to have failed in research and development, and the QQ password bug caused heated discussion. Wei Lai responded to the short selling rumors. Today, more big news is here
从0使用keil5软件仿真调试GD32F305
Deploy lvs-dr cluster
Leetcode question brushing (III) -- binary search (go Implementation)
05_Node js 文件管理模块 fs
ionic4 ion-reorder-group组件拖拽改变item顺序
我在鹅厂淘到了一波“炼丹神器”,开发者快打包
I found a wave of "alchemy artifact" in the goose factory. The developer should pack it quickly
ArcGIS PRO + PS vectorized land use planning map
R语言plotly可视化:使用plotly可视化多分类模型的预测置信度、模型在2D网格中每个数据点预测的置信度、置信度定义为在某一点上最高分与其他类别得分之和之间的差值
六月集训(第30天) —— 拓扑排序
ArcGIS Pro脚本工具(6)——修复CAD图层数据源