当前位置:网站首页>Those confusing concepts (3): function and class
Those confusing concepts (3): function and class
2022-07-07 10:38:00 【xinxin_ csdn】
ES6 Medium class class (oop Object-oriented programming ideas ) and function difference
The same thing :
Can be used as a constructor , adopt new Operator to instantiate
Function implementation constructor
function Person(name) {
this.name = name
}
const user = new Person('Jack')
console.log(user); // Person { name: 'Jack' }Constructor class implementation , Among them constructor Method is a special method , Called constructor method ;
use new After creating the instance , Automatically call constructor, Does not define constructor, amount to constructor It's a null function
class Person {
constructor(name) {
this.name = name
}
}
const user = new Person('Jack')
console.log(user); // Person { name: 'Jack' } Difference
1、 Calling a class constructor must use new The operator , And ordinary. function Constructor if not used new, Will take the overall situation this, As internal objects
2、function Constructor declaration has variable promotion , You can use it first , class Declare that there is no variable promotion , The instantiated object must be written after the declaration
const user = new Person('jack')
function Person(name) {
this.name = name
}3、class Not available call、apply、bind change this Point to
边栏推荐
- How to successfully pass the senior system architecture designer in the second half of the year?
- 深入理解Apache Hudi异步索引机制
- Experience sharing of software designers preparing for exams
- When do you usually get grades in the soft exam? Online pedaling?
- BigDecimal value comparison
- 长列表性能优化方案 memo
- 使用 load_decathlon_datalist (MONAI)快速加载JSON数据
- CSAPP Bomb Lab 解析
- 1321:【例6.3】删数问题(Noip1994)
- Basic introduction of yarn and job submission process
猜你喜欢
![1321: [example 6.3] deletion problem (noip1994)](/img/bd/b605ec7b901079a9ebaca446fad7fb.png)
1321: [example 6.3] deletion problem (noip1994)

01 use function to approximate cosine function (15 points)

openinstall与虎扑达成合作,挖掘体育文化产业数据价值

Socket communication principle and Practice
![[recommendation system 01] rechub](/img/92/c14c867247d3a042c69b5ed0091fbe.png)
[recommendation system 01] rechub

如何顺利通过下半年的高级系统架构设计师?

Some properties of leetcode139 Yang Hui triangle

使用 load_decathlon_datalist (MONAI)快速加载JSON数据

Applet jump to H5, configure business domain name experience tutorial

php \n 换行无法输出
随机推荐
@Configuration, use, principle and precautions of transmission:
Study summary of postgraduate entrance examination in November
[recommendation system 01] rechub
1324:【例6.6】整数区间
CAS机制
根据设备信息进行页面跳转至移动端页面或者PC端页面
Adb 实用命令(网络包、日志、调优相关)
原型与原型链
想考中级软考,一般需要多少复习时间?
Cluster task scheduling system lsf/sge/slurm/pbs based on HPC scenario
打算参加安全方面工作,信息安全工程师怎么样,软考考试需要怎么准备?
[detailed explanation of Huawei machine test] tall and short people queue up
Socket通信原理和实践
【推荐系统 02】DeepFM、YoutubeDNN、DSSM、MMOE
P1223 queuing for water /1319: [example 6.1] queuing for water
[STM32] solution to the problem that SWD cannot recognize devices after STM32 burning program
The variables or functions declared in the header file cannot be recognized after importing other people's projects and adding the header file
P1031 [noip2002 improvement group] average Solitaire
When do you usually get grades in the soft exam? Online pedaling?
Study summary of postgraduate entrance examination in August