当前位置:网站首页>JSCORE day_ 04(7.5)
JSCORE day_ 04(7.5)
2022-07-27 00:48:00 【Add 1 bed of bedding】
review
yi Precise configuration of objects :
Advanced knowledge points : You can accurately configure the properties of objects
configurable: Reconfigurable
writable: New values can be written
enumerable: Ergodic --
for...invalue: value
get: Compute properties . The value of the property is a function , You don't need () It will automatically trigger
set: Monitor . Property becomes a function , Receive the value passed in by the assignment operation , To test
Satisfy : Storage Attributes made for storing data , The name is usually
_???dissatisfaction : Report errors
How to protect objects
Prevent increase : preventExtensions
Prevent additions and deletions : seal
Prevent addition, deletion and modification : freeze
Arrow function : More convenient anonymous function format
Grammatical sugar :
There is only one formal parameter , () Omit
The function body has only one line , It can be omitted return and {}
this Point to :
No, this, Use the upper scope this-- Prototype chain mechanism
Template string
ES6 New string enhanced syntax
Optimized string splicing :
${}Support line break : The main response is HTML Multiple lines of code
Array higher order functions : Higher order - Other functions are used in the function
every: Everyone is satisfied
some: At least one satisfies
filter: Filter out those that meet the conditions
map: mapping -- The return value after processing the array elements , Make a new array
One 、 Higher order function forEach
About traversing arrays , Now there are at least four
![]()
Traditional scheme : for loop

for...in: General scheme of traversing object types ; Array is a special object

ES6: Provides for..of Specifically for traversing arrays , And for..in The difference is that it directly traverses the value , There is no serial number

ES6: Provide an array of Higher order function forEach, Be careful : Different from other higher-order functions , It has no return value , Just traverse

application forEach A case of

Two 、reduce
The traditional way

reduce The way

reduce: Array element merging , Pay attention to the meaning of parameters

3、 ... and 、let And const


ES6 Before , Declared variables are only var and function, There is a global pollution risk : Directly declare in the script that it will appear in window In the object ;ES6 Provided in the let and const key word .
1. Declared variables are stored in Script scope ( New scope ), The script scope must be viewed with the breakpoint technique .

2. let Declare changeable ;const declare constant : It cannot be changed after the declaration - More secure , More efficient .
Case study : Choose what statement to use according to the situation ?
Daming's salary salary -- The prediction may change in the later stage ; Daming's wife wife -- Expect no change in the future

Theoretical priority : const > let no need var
3. About declaration promotion ( Interview questions . a key )
const and let There are statements to improve , But exist “ Temporary deadband ” Set up . First , Declare that promotion is not a good design , So the author has to make changes ; however , The declaration of ascension is deeply rooted , Directly modifying its source code has too much influence ; So the author provides an error report , You have to declare it before you use it , Otherwise, the backstage will be popular .
let/const Variable , Before declaring code execution , be called Temporary deadband state -- Temporary promotion , however A dead state , Not allowed to use . Can only be used after declaring code execution

Four 、 Block level
Block level scope : Used instead of closures
Closure : Create a function scope with anonymous functions , Declare variables in it For other functions
Block level : use {} coordination let/const Use

ES6 Before that, we used closures

Some grammars come with {}, Can form a block level , To avoid global pollution for if while switch All have their own block level
myth : function {} Function scope
object {}: Although there are {} But I didn't write it let The grammar of

5、 ... and 、 Expand grammar :...
Merge two arrays using “ ... ” Remove the outer layer of the array [ ]

Application scenarios , For example, in the use of max Function time , It only accepts Pass in numbers one by one as parameters , Do not accept arrays , Find the maximum value in an array , Just use the expansion grammar .

alike , Objects can also use expansion syntax , But it encounters an attribute with the same name , What you write later will cover what you write first .

6、 ... and 、 deconstruction
Optional deconstruction : Just the first and the last one

When we store the elements in the array in a b c d Among the four variables , Using deconstruction syntax is much more convenient , You don't have to write a code for each element .

Flexible application scenarios : Values of interchangeable variables , Originally, we need to define another variable to store data , But now it's not needed . But here's the thing , After declaring variables, you need to use semicolons to separate the code that deconstructs the syntax , Prevent the value assigned to the variable in front of the printout .

When we need to read out the attributes in the object , Deconstruct two properties , You can also use alias syntax : Deconstruct the attributes Change your name , Format ---- “ Property name : Alias ”.

In actual combat : The requested data is usually object Doped array Structure , It can also be deconstructed .

Array Can also deconstruct

Parameters of deconstruction

js turn html+ Parameters of deconstruction

7、 ... and 、 Parameter default
ES6 Function enhanced syntax : Parameter default . When no arguments are passed , The default value of the formal parameter ; When passing arguments , Then use the passed in value Instead of default .

8、 ... and 、 The remaining parameters of the function
The remaining parameters : Than arguments More powerful And flexibility
arguments: Receive and store all arguments
shortcoming 1: Implicit , Some programmers don't know arguments The existence of
shortcoming 2: Pseudo array type , There are no array related methods
ES6 New syntax : use ... Variable name Explicitly declare parameters , Receive all arguments
this ... and Previous expansion ... It doesn't matter , It's just the same in appearance

边栏推荐
- 5_ Linear regression
- JSCORE day_05(7.6)
- 10个Web API
- [qt] container class, iterator, foreach keyword
- Elaborate on the differences and usage of call, apply and bind 20211031
- 运算符重载
- 2020-12-22最大公因数
- Consistency inspection and evaluation method kappa
- [Network Research Institute] attackers scan 1.6 million WordPress websites to find vulnerable plug-ins
- Medical data of more than 4000 people has been exposed for 16 years
猜你喜欢

c语言 static运用,灵活改变生命周期,让你写代码如鱼得水

The use of C language static can flexibly change the life cycle and make you write code like a duck to water

Consistency inspection and evaluation method kappa

6_梯度下降法(Gradient Descent)

postman的使用
![[NPUCTF2020]ezinclude](/img/24/ee1a6d49a74ce09ec721c1a3b5dce4.png)
[NPUCTF2020]ezinclude

Use csrftester to automatically detect CSRF vulnerabilities

Parallel MPI program delivery send message
![[WUSTCTF2020]CV Maker](/img/64/06023938e83acc832f06733b6c4d63.png)
[WUSTCTF2020]CV Maker

C语言 关机小程序
随机推荐
QML type system
运算符重载
【2. Tmux 操作】
[acwing game 61]
【4.3 欧拉函数详解】
10个Web API
CDs simulation of minimum dominating set based on MATLAB
[4.9 detailed explanation of inclusion exclusion principle]
Drawing warehouse-2 (function image)
简单的素数程序 初学者 希望码龄高的大佬可以一下
In JS, the common writing methods and calling methods of functions - conventional writing, anonymous function writing, taking the method as an object, and adding methods to the object in the construct
用New,delete和用malloc,free申请,释放堆区空间
Leetcode high frequency question: the choice of the inn, how many options to choose accommodation, to ensure that you can find a coffee shop with a minimum consumption of no more than p yuan in the ev
我的第一篇博客-迷茫的大三人
Two or three things about redis
6_ Gradient descent method
[4.7 Gauss elimination details]
Friend friend function and singleton mode
Blue Bridge Cup 1004 [recursive] cow story
DOM day_04(7.12)BOM、打开新页面(延迟打开)、地址栏操作、浏览器信息读取、历史操作