object
closure
closure=inner function+external function variable
function f1() { let i=0 function f2() { i++ console.log(i) } return f2}const f=f1()
construct object
function Pig(name,age,gender){ this.name = name this.age = age this.gender = gender }const pappe = new Pig('佩奇',6,'女')
Instance members: methods and properties on property objects
Static members: static properties and methods
convention
- can only start with a capital letter
- can only be executed using the ‘new’ operator
prototype
function Pig(name,age){ this.name = name this.age = age }Pig.prototype.sing=function(){}const pappe = new Pig('佩奇',6)
- each cpmstructor has a prototype property
- This object mounting function will not create functions on the prototype multiple times during object instantiation, saving memory
constructor
- Refers back to the constructor created
object prototype
__proto__
=[[proto]]
inherit
function Person(){ this.gender=1}function A(uname,age){ this.uname = uname; this.age = age;}A.prototype=new Person()A.prototype.constructor=A
Prototype Chain
Inheritance based on prototype objects associates different constructor objects together
instanceof
You can use instanceof
to check if the prototype property of the constructor appears on the prototype chain of an instance object
function
parmeter
-
dynamics parmeter
argumentsThe paseudo array includes all the parameters passed in
-
remaining parameters
function f(...<parameter name>){<parameter name> //array}
Arrow function
const <function name> = () =>{}
rule
- If the function has only one line, it can be written on one line, {} can be omitted, and there is no need to write a return to have a return value. If the return dictionary needs to be written, () needs to be added
- if there is only parameter,()can beomitted
this
the arrow function does not have this,it wil only use this from the higer-level scope chain
deconstruction
{name:newname,age:newage}={name:lsy;age:19}
- The variable names for deconstruction need to be consistent with those in the object
- Rename: The previous name is the opposite name, followed by the new name that needs to be changed. If not changed, do not use write
multistage
obj={ a:1 b:{ b1:2 b2:3 } c:4}{a,b:{b1,b2},c}=obj
array
Expand operator
...<array>
deconstruction array
[a,b]=[1,2]
- Assign the variables on the left to the variables on the right in sequence
- Support multidimensional arrays
copy
shallow copy
If it is a complex data type, only copy the address
-
object
Object.assign(<new>,<old>) -
array
Array.prototype.concat()
deep copy
- recursion
- json
- Library functions
performance optimization
explain | |
---|---|
debounce | Frequent triggering of events within a unit time, only executing the last time |
throttle | Frequent triggering of events per unit time, only executed once |