当前位置:网站首页>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
边栏推荐
- Leetcode-304: two dimensional area and retrieval - matrix immutable
- Five simple and practical daily development functions of chrome are explained in detail. Unlock quickly to improve your efficiency!
- 使用U2-Net深层网络实现——证件照生成程序
- P1031 [noip2002 improvement group] average Solitaire
- Socket communication principle and Practice
- [système recommandé 01] rechub
- ThreadLocal is not enough
- table宽度比tbody宽度大4px
- MONAI版本更新到 0.9 啦,看看有什么新功能
- What is an intermediate network engineer? What is the main test and what is the use?
猜你喜欢

枪出惊龙,众“锁”周之

The variables or functions declared in the header file cannot be recognized after importing other people's projects and adding the header file

原型与原型链

Trajectory planning for multi-robot systems: Methods and applications 综述阅读笔记

Socket communication principle and Practice

Leetcode-304: two dimensional area and retrieval - matrix immutable

ArrayList thread insecurity and Solutions
![P1031 [NOIP2002 提高组] 均分纸牌](/img/ba/6303f54d652fa7aa89440e314f8718.png)
P1031 [NOIP2002 提高组] 均分纸牌

leetcode-560:和为 K 的子数组

Use the fetch statement to obtain the repetition of the last row of cursor data
随机推荐
【机器学习 03】拉格朗日乘子法
多线程-异步编排
MONAI版本更新到 0.9 啦,看看有什么新功能
[homework] 2022.7.6 write your own cal function
TypeScript 接口继承
[recommendation system 01] rechub
Study summary of postgraduate entrance examination in September
Is the soft test intermediate useful??
Schnuka: machine vision positioning technology machine vision positioning principle
HDU-2196 树形DP学习笔记
[recommendation system 02] deepfm, youtubednn, DSSM, MMOE
CAS mechanism
555电路详解
中级软件评测师考什么
求方程ax^2+bx+c=0的根(C语言)
Gym installation pit records
Prototype and prototype chain
施努卡:机器人视觉抓取工作原理 机器视觉抓取
I'd rather say simple problems a hundred times than do complex problems once
长列表性能优化方案 memo