当前位置:网站首页>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

边栏推荐
- [NPUCTF2020]ezinclude
- 裁剪tif影像
- Blue Bridge Cup 1004 [recursive] cow story
- el-checkbox中的checked勾选状态问题 2021-08-02
- 寻找真凶
- Matlab simulation of inverted pendulum control system based on qlearning reinforcement learning
- Looking for the real murderer
- 【4.2 约数】
- The use of C language static can flexibly change the life cycle and make you write code like a duck to water
- [leetcode] no duplicate longest string
猜你喜欢

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

Install redis-7.0.4 in Linux system

3_Jupyter Notebook, numpy和matplotlib

Use csrftester to automatically detect CSRF vulnerabilities
![[WUSTCTF2020]CV Maker](/img/64/06023938e83acc832f06733b6c4d63.png)
[WUSTCTF2020]CV Maker

裁剪tif影像

关于Thymeleaf的表达式

Helicopter control system based on Simulink
![[Qt]容器类、迭代器、foreach关键字](/img/88/d9d5be096009b4e5baa0966e6f292c.jpg)
[Qt]容器类、迭代器、foreach关键字

DOM day_ 04 (7.12) BOM, open new page (delayed opening), address bar operation, browser information reading, historical operation
随机推荐
Apply with new, delete and malloc, free to free the heap space
Torch. correlation function
[HITCON 2017]SSRFme
8_多项式回归及模型泛化(Polynomial Regression and Model Generalization)
2022.DAY600
【4.3 欧拉函数详解】
[qt] solve the problem of Chinese garbled code
寻找真凶
2020-12-20 九九乘法表
js检测屏幕的方法总结 2021-10-05
MySql
Huffman encoding and decoding
Friend友元函数以及单例模式
【4.2 约数】
[Qt]元对象系统
动态联编和静态联编、以及多态
Use of postman
JSCORE day_04(7.5)
MySQL associative table queries (reducing the number of queries)
【Codeforces Round #808 (Div 2.) A·B·C】