JavaScript Ninja Cheats Version 2

console.time(“jj”)

undefined
console.timeEnd(“jj”)
VM1738:1 jj: 73327.87915039062 ms
undefined

Babel conversion compiler

2 The construction process of the runtime pageInsert picture description here

The global object exposed by the browser to the js engine is the window object. Represents a page window. The window object is a way to get other global objects, variables, and browser APIs.

As long as there are unprocessed HTML elements and unfinished JS code, these two steps will be executed: 1. Build HTML into DOM 2. Execute JS code
After the browser processes all HTML elements, the page construction phase ends. , Enter the event processing stage.

2.3 Event handling

All generated events are placed in the event queue, in the order in which they are detected by the browser.

Detect the event at the head of the queue
If no event is detected, continue to detect the event is detected
, take out the event and execute

Insert picture description here
Register event handler

  • Assign the function to the attribute.οnclick=
    Not recommended, only one event handler can be registered for an event
  • addEventLIstener()

Insert picture description here

/

Number: definition and parameters

3.1.2 Callback function

Pass a function as a parameter to another function,

3.2.1 Stored functions

The method of storing in an array, looping the array to traverse and de-duplicate the performance is poor,
storing in the properties of the object

var store={
    
    

}

3.2.2 Self-memory function

Be able to remember the result of the last operation. When the function calculates the result, it stores the result as a parameter.
If another call also uses the same parameters, you can return to the last stored result without having to recalculate it.

3.4.1 Remaining parameters

fu/ction aa(…bb){
console.log(bb)
}+
aa(1,2)

4 Function call

Implicit function parameters: this, arguments
this context object for calling the function.

4.1.2 this

4.2 Function call

Function call method has a great influence on the execution of function code

4 ways to call functions

Call aa() directly as a function function

        function aa(){
            function bb(){
				"use strict"
                console.log(this)
            }
            bb()
        }

In non-strict mode, this is the global context window. In
strict mode, undefined

As a method method, associated with an object to implement object-oriented programming nn.aa()

The object becomes the context of the function

As a constructor constrcutor, instantiate a new object new aa()

function whatMyContext(){
    
    
	return this
}
function Nn(){
    
    
	this.sk=function (){
    
    
		return this
	}
}
Nn() 
let b=new Nn()
//
b.sk()===b

When called by the new keyword, an empty object instance is created and passed to the function as the function context this. When the attribute of creating an sk on the object is assigned to a function in the constructor, the function becomes a method of creating a new object.

Constructor return value

  • Through function apply, call method aa.apply(nn) or aa.call(nn)

Guess you like

Origin blog.csdn.net/cs18335818140/article/details/110038840