当前位置:网站首页>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
边栏推荐
- About hzero resource error (groovy.lang.missingpropertyexception: no such property: weight for class)
- Openinstall and Hupu have reached a cooperation to mine the data value of sports culture industry
- 使用 load_decathlon_datalist (MONAI)快速加载JSON数据
- [recommendation system 01] rechub
- 【推薦系統 01】Rechub
- IIC Basics
- ThreadLocal会用可不够
- Leetcode-303: region and retrieval - array immutable
- P2788 math 1 - addition and subtraction
- Jump to the mobile terminal page or PC terminal page according to the device information
猜你喜欢

成为优秀的TS体操高手 之 TS 类型体操前置知识储备

CSAPP Bomb Lab 解析

Five simple and practical daily development functions of chrome are explained in detail. Unlock quickly to improve your efficiency!

CAS mechanism

【推荐系统 02】DeepFM、YoutubeDNN、DSSM、MMOE

优雅的 Controller 层代码

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

Experience sharing of software designers preparing for exams
![1324: [example 6.6] integer interval](/img/5d/29db4d51ec7a2685f8aeffe5be68da.png)
1324: [example 6.6] integer interval
![P1031 [NOIP2002 提高组] 均分纸牌](/img/ba/6303f54d652fa7aa89440e314f8718.png)
P1031 [NOIP2002 提高组] 均分纸牌
随机推荐
Schnuka: machine vision positioning technology machine vision positioning principle
Is the soft test intermediate useful??
高级软考(网络规划设计师)该如何备考?
Study summary of postgraduate entrance examination in July
【PyTorch 07】 动手学深度学习——chapter_preliminaries/ndarray 习题动手版
深入理解Apache Hudi异步索引机制
table宽度比tbody宽度大4px
01 use function to approximate cosine function (15 points)
Using U2 net deep network to realize -- certificate photo generation program
【作业】2022.7.6 写一个自己的cal函数
@Transcation的配置,使用,原理注意事项:
Trajectory planning for multi robot systems: methods and Applications Overview reading notes
Network engineer test questions and answers in May of the first half of 2022
无法打开内核设备“\\.\VMCIDev\VMX”: 操作成功完成。是否在安装 VMware Workstation 后重新引导? 模块“DevicePowerOn”启动失败。 未能启动虚拟机。
Common shortcut keys in IDA
[recommendation system 02] deepfm, youtubednn, DSSM, MMOE
How to prepare for the advanced soft test (network planning designer)?
Multithreaded asynchronous orchestration
那些易混淆的概念(三):function和class
软考一般什么时候出成绩呢?在线蹬?