This is the 29th day of my participation in the August Wenwen Challenge.More challenges in August
window.getComputedstyle(element,pseudoElement)
Elemet. style is used to obtain the style of an element, which is not the same as elemet.style. Element. style is used to obtain the style of an element, but this method can only obtain the style of all elements. So we usually use this method to read and then modify the style with element.style
className classList
element.style window.getComputedstyle
- HTML/Css/Js does its job
- Unnecessary direct manipulation of styles by JS should be avoided
- You can use class to represent state
- Pure presentation class interaction seeks zero JS scheme
Anti-shake and throttling: limits the number of times a function can be executed
When your function is called multiple times, we need to use this knowledge
TDZ(Temporary Dead Zone) : Variables declared by lets and const are not promoted to the top of scope. Accessing these variables before the declaration causes an error, because the JavaScript engine either pushes them to the top of scope when it scans the code for variable declarations (var declarations are encountered), Either put the declaration in TDZ (where let and const declarations are encountered). Accessing variables in TDZ triggers a runtime error. Variables are removed from the TDZ and can be accessed only after a variable declaration statement has been executed
Object.freeze(x)
The object.freeze () method freezes an Object. A frozen object can no longer be modified. If you freeze an object, you cannot add new attributes to the object, delete existing attributes, modify the enumerability, configurability, writability of existing attributes of the object, or modify the value of existing attributes. In addition, the stereotype of an object cannot be modified after it is frozen. Freeze () returns the same object as the argument passed in.
Value and address transmission
Primitive type replication is a copy of values that does not affect each other. In the following example, after assigning the value of variable A to variable B, a change in variable A does not affect the value of variable B because the base type variables are independent.
let a = 100;
let b = a;
a = 200;
console.log(b);
Copy the code
For reference types, variables hold Pointers to reference objects. Assignments between variables are actually Pointers to variables, so that multiple variables refer to the same object.
Let a = {web: "backer"}; let b = a; a.web = "hdcms"; console.log(b);Copy the code
for/in
For /in is used to iterate over all attributes of an object. For /in is used to iterate over an object, not a number group.
Iterate over the number group operation
for/of
Iterate over iterable data structures like Arrays, Strings, Maps, and Sets.
Unlike for/in, for/of takes the value of each loop instead of the index.
Case conversion
Converts characters to uppercase format
console.log('houdunren.com'.toUpperCase()); //HOUDUNREN.COM
Copy the code
The conversion character is in lowercase format
console.log('houdunren.com'.toLowerCase()); //houdunren.com
Copy the code
Functions using let/const are not pushed into the window
Parameter arguments
Parameters are parameters that are set when a function is declared, and arguments are values passed when a function is called.
- If the number of parameters is greater than the actual parameter, the parameter that is not passed is undefined
- When the number of arguments is greater than the parameter, the additional arguments are ignored and no errors are reported
Get attribute name
Use Object. GetOwnPropertyNames collection can get Object property names
Let the hd = {name: 'backing people' year: 2010} const names = Object. GetOwnPropertyNames (hd) console. The log (names) / / / "name", "year"Copy the code
Task queues are divided into synchronization task queues of the main thread, macro task queues, and micro-task queues
Main task queue > micro task queue > macro task queue
Promises are put into the microtask queue
Timers are put into the macro task queue
When the task queue in asynchronous tasks, will carry out the tasks of the main thread, then the timer will perform at the same time, when the timer is done, will be put into the macro task queue, and then the main thread, such as the completion of the task, to perform the task queue, when the micro task queue tasks are performed, to carry out macro task queue
Call () changes the direction of this and executes the call immediately