当前位置:网站首页>What happens to the new arrow function in ES6
What happens to the new arrow function in ES6
2022-07-27 05:41:00 【weixin_ forty-six million fifty-one thousand two hundred and si】
1)new Keyword execution process
- new After constructor , An empty object will be created in memory
- this It will point to the empty object just created
- Execute code in constructor , Add attribute methods to empty objects
- Return this new object ( So... Is not required in the constructor return)
2) Arrow function
In the arrow function this Is static , Point to the object where it was defined , It will not be the object at the time of call ,this The direction cannot be changed
var age=18
var obj={
age:20,
getAge(){
// Constructors , Who is calling ,this Just point to who
console.log(this.age);
},
getAge1:()=>{
//this Is static , Point to the object where it was defined (window object ), Can't be a constructor
console.log(this.age);
},
}
obj.getAge()//20
obj.getAge1()//18
边栏推荐
猜你喜欢

GalleryCMS下载安装与配置

页面的基本布局

Share a multiple-choice question about the process of program compilation (including a brief discussion on the compilation process, the formation and merging process of symbol tables)

程序环境和预处理(上):一个程序是怎么成功运行的?

页面布局中元素定位的几种方式

页面的配置

一本通顺序结构程序设计题解(第一章)

Exit login and JSX display

路由的配置和前往登录首页进行发送请求

分享一道关于变量的选择题(内含全局变量、局部变量、变量的作用域、生命周期知识点)
随机推荐
SQL (MySQL) rookie tutorial knowledge
Think about the role of some documents
C language string function: strlen, strcpy, strcat
dirsearch[目录扫描工具]
Program environment and preprocessing (Part 1): how does a program run successfully?
JS中&&(与)和||(或)操作符的返回值
[CISCN2019 华东南赛区]Web11 1
JS如何判断一个对象是否属于一个类
[C language switch branch statement and loop statement]
C语言函数入门介绍
Exit login and JSX display
块,行内块元素之间存在间隙
「PHP基础知识」PHP中实现数学运算
编辑删除用户
Page configuration
程序环境和预处理(下):#define、#undef、命令行编译、条件编译、文件包含(超全整理,建议收藏!!!
初识C语言——常量、变量
Introduction to C language functions
Configure the route and go to the login home page to send the request
程序环境和预处理(上):一个程序是怎么成功运行的?