javascript knowledge review

--- --- restore content begins

1.js garbage collection

  Will be marked as "away environment" When the variable into the execution environment will be marked garbage collector is "into the environment", leaving the execution environment, wait until the garbage collector runs all the variables to be stored in memory:. A mark Clear add tags, and then remove the environment variables, and markers are referenced by the environment variable variable left is the variable to be deleted mark exists. (IE use)

  . B reference count: declare a variable and a reference value plus the number assigned to the type of the reference variable, if the value of the variable is decremented by a reference to the other, a reference value when the number of times it reaches zero recovery will take up memory space (BOM and use the DOM), the disadvantage is likely to cause a memory leak.

Composition of 2.js

  ECMAScript, DOM, and BOM

  DOM: Document Object Model, so you can access it through the elements of the HTML document.

  BOM: browser object model, which is the ability to work with browser js through dialogue.

  ECMAScript: core component, the specification is js, js achieve the ECMAScript.

3. What is the origin policy, why have homologous limit.

  Homologous refers to the protocol, the domain name and the same port. It is a convention, is the core browser is the most basic security, if there is no same-origin policy, the browser will receive the normal function may affect.

4. How cross-domain request

  The first way: jsonp request; JSONP principle is to use <script> tag characteristic cross-domain, unlimited load resources from other domains, there is a similar tag <img>.

  The second embodiment: document.domain; domain access this manner different primary domain in the same subdomain

  The third way: window.name; attribute name window are features: in a window (window) of the life cycle, the window size of all pages are sharing a window.name each window on the page. name has read and write permissions, window.name is persistent over a window loading all pages, and new pages will not load and reset.

  The fourth embodiment: window.postMessage; window.postMessages is a new way to implement cross-domain access html5, can use it to send messages to other objects in the window, the window object, whether they are homologous or different sources.

  Fifth way: CORS; CORS basic idea behind is to use a custom HTTP headers allow the browser to communicate with the server to determine the success of the request or response should or should fail.

  Sixth ways: Web Sockets; web sockets Principle: After JS created a web socket, there will be a HTTP request is sent to the browser to initiate a connection. After obtaining the server response, connections can be made using HTTP upgrade from HTTP protocol to exchange web sockt agreement.

5.js lazy loading and preloading

  Lazy loading: also known as lazy loading, including the defer and asyns, is to implement the principle of background img pictures or other elements into a fixed-size footprint map only when the position of the picture into the viewing area will be set true picture path load.

  Pre-loaded: Load picture ahead, rendering can be extracted when a user views directly from the Local.

6. Events and event mechanism

  Event: Web event is caused by an operation in the event source

  Event mechanism: event bubbling (by the specific elements of the window) and event capture (by the window to a particular element), is to prevent ev.stopPropagation () Note that older versions of IE method is ev.cancelBubble = true..

7. event listener and event agency (event delegate)

  Event listeners: an event listener to solve common event before the event binding event action overrides, dom objects .andEventListener (event, function, capture). capture = false executed in the bubbling phase, capture = true executed during the capture phase.

  Event delegates: Also called the event broker to resolve multiple acquisitions DOM manipulation elements, use event bubbling mechanism to achieve.

8. function declarations and function expressions

  Function declaration: function demo (e) {return e == type}

  Function expression: var demo = function (e) {return e == type} 

  Different points: the Javascript function declarations and function expressions is there is a difference, and a function to enhance the function declaration in the JS parsing, so in the same scope, regardless of where the function declaration defined, this function can be called. The value of the function expression is determined at JS run time, and after the expression evaluation is completed, the function can be called.

9. Closure

  Functions have access to another function scope variables

10. Regular Expressions

  Description string to match the pattern of features specific string.

11.IE and DOM event flow

  IE uses a bubbling event (button-> div-> body), DOM is used to capture the bubble (body-> div-> button-> button-> div-> body).

  Use IE: [Object] .attachEvent ( "name_of_event_handler ", fnHandler); // binding function
         [Object] .detachEvent ( "name_of_event_handler" , fnHandler); // bind to remove

  DOM used:
      [Object] .addEventListener ( " name_of_event ", fnHandler, bCapture); // binding function
      [Object] .removeEventListener (" name_of_event " , fnHandler, bCapture); // bind removed

And how to determine the node type 12.js

  Node types are element nodes, attribute nodes, text nodes, comment nodes, document nodes.

  NodeObject.nodeType used to determine the node, nodeObject a DOM node, which returns the node type represented numerically.

13.js variable types and how to judge

  Variable data types are number, string, boolean, null, undefined. Reference type number, object, array

  With typeof to determine the type of the variable, is used to determine instanceof object is not instantiated class (if an object of another class is constructed).

14.js prototype chain

  In javascrip Prototype Each object has a property called a prototype, but is a target value of the prototype, it also has its own prototype This prototype series up a chain, the first chain strand is the Object prototype, its prototype comparison special value is NULL.

  The role of the prototype chain is used to inherit

 

 

 

 

 

 

 

 

 

 

 

 

  

 

--- end --- restore content

Guess you like

Origin www.cnblogs.com/newCoo/p/11140158.html