Home > front end >  Js interview question 2
Js interview question 2

Time:10-10

What is the difference between IE with DOM event flow
(1) in this paper, the ways of binding events:

Internet explorer 9 before: attachEvent (" onclick "), detachEvent (" onclick ")

Ie 9 with DOM event flow is the same, are addEventListener

(2) the difference between these two kinds of binding way: the difference between written:

AttachEvent two parameters, events take on

AddEventListener three parameters, don't take on events, true/false said capture/bubbling

The difference of function:

AttachEvent all binding event bubbling addEventListener, according to the third parameter is true or false decided the bubbling or capture,

(3) event bubbling and event capture, bubble: when the trigger an event, will start from the current node, with the types of events, in turn, trigger the ancestor nodes, capture: starting from the root node, in turn, trigger the ancestor nodes with the type of event, until the node itself,

2 Internet explorer and under what compatibility of standard way?
Copy the code
Ev=e | | window. The event;//to get event object factor (events) : add DOM2 events: the if (dom) attachEvent) {dom. AttachEvent (" onclick ", function); } else {Dom. AddEventListener (" click ", the function). } canceling event bubbling: if (e.s topPropagation) {e.s topPropagation ();//IE outside} else {e.c. with our fabrication: ancelBubble=true;//IE8} before cancel the default event: the if (e.p reventDefault) {e.p reventDefault ();//IE outside} else {" e.r eturnValue=https://bbs.csdn.net/topics/false;//IE}

Copy the code
3 API is what? API (Application Programming Interface, Application Programming Interface) is a function of some predefined, the purpose is to provide the Application based on a software or hardware to developers to access the ability of a set of routines, without access to the source code, or understand the details of the internal working mechanism, in Programming languages, apis usually refers to the language of the built-in functions, Interface, system tools, such as, we programmers do not need to care about the function of the implementation details, only need according to the requirements of the API documentation, to the function to accept the return value can be specified parameters, transfer data in Taiwan before and after, the API is also provided to the front desk the Interface of the background, the front desk need only request Interface and send the parameters specified in accordance with the requirements, and accept a JSON string class, for example: https://api.douban.com/v2/book/1220562

4 javascript event handler will not run before the idle thread is what mean? JS is a single-threaded applications, that is to say, when a piece of code is executed, if you need to perform other code must also wait until the end of this thread, to perform,

for(var i=1; i<=3; I++) {setTimeout (function () {the console. The log (I); }, 0); }; Code execution to the for loop, when the for loop to perform for the first time, hit the first setTimeout does not immediately trigger, because of the for loop and end, the thread is now a for loop blocking, setTimeout must wait until after the for loop threads, thread is idle, to perform, and this time I had become a 4. So eventually print three 4. The solution can change var to let, or nested for loop since the caller and the callee role in executive function 5 js writing different:

The callee is a property of the Arguments used in the function Arguments. The callee calls,

Caller in function, the direct use of the function name calls, Func. Caller function different:

The Arguments. The callee returns, the current function itself reference!!!!

Func. The Caller is returned, the current function in which function calls, if the function is the top call, it returns null

Copy the code function func () {the console. The log (func. Caller); } func ();//null function func1 () {func (); } func1 ();//return func1
Copy reserved words in 6 js code is what predefined keywords in the program (the function name, the name of the class, the property name, method names and other identifiers) is a reserved word in js, these reserved words, does not allow users to once again as a variable, method, function reserved words will change color in the compiler, 7 factories create js object is what way (js) to create objects in many ways
1) literal pattern: var obj={} mixed mode is what we call add attributes to the member attribute (constructor mode), the method is added to the prototype method (prototype mode) 8 js lazy-loading way have? http://blog.csdn.net/dragoo1/article/details/48155501 + put JS code document one of the last and lazy loading way,

What is the difference between 9 documen. Write and innerHTML? Documen. Write is directly in the entire document, write code that will overwrite other existing code, innerHTML is selected after a node, the node code inside, affects only the current node,

10 the garbage collection mechanism in the javascript? The closure of the memory release? The garbage collection mechanism in the Js, a variable in a function, the function, after the completion of execution by recycling, however, if a function is used in the closure, so a variable in a function will always be the internal function holds, not in function after the completion of the release, http://www.cnblogs.com/zhwl/p/4664604.html closure of two important functions: (1) can make a function outside, to be able to access functions internal variable, (2) make function, after the completion of the internal variables in the function of will not always stay in memory is released,

11 what can cause a memory leak extensive use of global variables, extensive use of closures is cleared when the DOM node, remove nodes only, and not delete events http://www.cnblogs.com/libin-1/p/6013490.html

12 the accuracy problems in js
JS in floating-point arithmetic or large integer arithmetic, can lead to inaccurate results, for example, 0.7 + 0.1=0.7999999999999 solution can add those Numbers * 10, and then divided by 10

http://www.cnblogs.com/snandy/p/4943138.html 13 defer and async
1. The default script reference: & lt; The script type="text/javascript" SRC="https://bbs.csdn.net/topics/x.min.js" & gt; </script> When the browser encounters script tags, document analysis will stop, and immediately download and execute the script, after the script execution will continue to parse the document,

2. The async mode & lt; Script type="text/javascript" SRC="https://bbs.csdn.net/topics/x.min.js" async="async" & gt; </script> When the browser encounters script tags, document parsing will not stop, other threads will download the script, the script download began to execute the script, after the completion of script execution will stop parsing process document, until completion of the script,

3. The defer (delay) model & lt; Script type="text/javascript" SRC="https://bbs.csdn.net/topics/x.min.js" defer="defer" & gt; </script> When the browser encounters script tags, document parsing will not stop, other threads will download the script, when a document parsing is complete, the script will perform,

http://www.cnblogs.com/xuechenlei/p/5947555.html and explain the CSS selector happen? [role=nav] & gt; Ul a: not (/href ^=mailto]) {}
[role=nav] role attribute is equal to the nav element in the selected pages. Is the navigation bar

[role=nav] & gt; Ul child nodes of the navigation bar ul

[role=nav] & gt; Ul a ul inside a tag

A: not (/href ^=mailto) select a label, in addition to using mailto beginning the href attribute,

Selected in the navigation bar ul is not mailto a label inside,
  • Related