The js event stream
1.1. Recognize the flow of events
JS event stream was first started from the browser war between IE and Netscape. IE proposed bubbling stream, while Netscape proposed capture stream. Later, under the unity of W3C, JS supports bubbling stream and capture stream, but the current low version of IE browser can only support bubbling stream (IE6,IE7,IE8 only support bubbling stream). In order to be compatible with more browsers, it is recommended to use bubbling streams.
1.2. Three phases of the event flow
Capture phase: When an element fires an event, the event is passed level by level from its top parent to the hanging element (from outside to inside), called event capture
Target phase: When an event is passed to this element, the event is fired, which is the target phase
Bubbling phase: After the element is found, the event is passed level by level from itself to the top parent element. This process is called event bubbling.
Second, js prototype chain
When the implementation of a method, will first from their own to find the method, no word to find their own prototype, their prototype has not, will find their parent class prototype, so, level by level to find, with known as the prototype chain.
At any level, if it is found, it will be called directly, instead of looking up. If it is not found at the end, an error will be reported.
Cookie, sessionStorage, localStorage
1. Both can be used to store data
Cookie the size of a data item cannot exceed 4KB and a maximum of 20 data items cannot be stored. If the expiration time is not set, the data item disappears after the browser is closed.
3. SessionStorage is a sessionStorage. The size of a sessionStorage cannot exceed 5M.
4. LocalStorage is a localStorage. The size of a localStorage cannot exceed 5M.
Four, Ajax
4.1. The principle of Ajax
An intermediate layer (Ajax engine) is added between the user and the server, sending asynchronous requests to the server via XMLHttpRequest instantiated objects, retrieving data from the server, and then updating the page with JS to asynchronize user actions and server responses.
4.2. Process
- Create an XMLHttpRequest object
- Creating an HTTP request
- Sets the function that responds to changes in the status of HTTP requests
- Send an HTTP request.
- Sets the statement to get the data returned by the server
- Local refreshes are implemented using JavaScript and DOM.
Five, deep copy, shallow copy
Suppose B copies A and see if B changes: if B changes, it is A shallow copy (the reference address is copied). If B does not change, it is A deep copy