"Experience" JavaScript

Source: Internet
Author: User
Tags event listener

Tag: let blink key const target relative off ToString Read

1.
function Closewin () {
window.open (', ' _self ');
Window.opener=null;
window.open (location, ' _self '). Close ();
Window.close ();
}
This is a closed window code that is compatible with the latest browser, but a page opened with the input URL under Chrome is not available for window.close (), which prompts scripts may close just the windows that were opened by it.

2. Add the attribute autocomplete= "off" to the input element to prevent Firefox from caching the INPUT element. It is said that the type= "hidden" input will encounter this problem.
3.
var a = {F:function F () {}};
Console.log (A.F);//f ()
Console.log (f);//referenceerror:f is not defined
4. There are two implementations of dependency injection, one that obtains a function string in the F.tostring method, a flaw in code compression, and an explicit injection to get parameters.
The scope of the 5.angularJS is associated with the DOM: the level of the scope is determined by the level of the DOM.
6.frameElement, framedocument is illegal variable name
The text in 7.HTML will contain "\ n", "" "," \ T "and so on, each of which counts as a character length, and if the console is used, it will be converted and displayed to the console.

8. (function () {} ()), var fn = function () {} () why not error and function () {} () error?
First, the conclusion and its derivation:
(1) The error of function () {} () is function statement requires a name
(2) The error of function f () {} () is expected expression, got ') '
(3) () The error is expected expression, got ') '
These three evidences indicate a conclusion: function () {} () will be executed as function () {};();
The reason should be: statements that begin with the "function" keyword are treated as function declarations


"Point 1: Yes {} not properly understood"
http://blog.csdn.net/woshinia/article/details/18666223
function () {} ()//anonymous function immediate execution, parsing period error
{}.constructor//Get the constructor of object's direct amount, parse period error
It is puzzling why [].constructor writes without error, a constructor that wants to get the direct amount of the object, and a constructor that gets the direct amount of the array.
Of course, add a variable to receive will not error
var c = {}.constructor;
The var fn = function () {} () does not error.
In fact, JS's "statement precedence" in the mischief, that is, {} is understood as a compound statement block instead of the object direct amount or the semantics of declaring the function.
"However, my test results do not support this statement, as follows"
function f () {} ()//firebug error syntaxerror:expected expression, got ') '
function A () {};();//Error Ibid.
();//error As above, this may be that the parentheses are interpreted as "expression grouping" instead of "function call". is not a question of curly braces.
"I think the reason is that the second pair () is not properly understood."
"But Http://www.cnblogs.com/snandy/archive/2011/03/08/1977112.html's comments are in favor of point 1."

http://www.zhcexo.com/round-brackets-in-javascript/
Example 3
(function () {
//...
})();

Example 4
(function () {
//...
}());

Example 3 is actually a function in the force operation parenthesis, the result of the operation is to return the function itself, the following parenthesis is the function of the call operator, to invoke the function of the forced operation.
In Example 4, the force operation of the parentheses allows the function to execute the call operation, and then returns the result of the call. While all can make function calls work, there is a small difference in the principle behind it.
Example 5
void function () {
//...
}();

Example 6
~function () {
//...
}();
void and ~ are unary operators, their operation priority is lower than the last parenthesis, but JS in the process of parsing, encountered void and ~, the following anonymous function will be recognized as operands, and their calculation priority is lower than the parentheses, so there is a function call, the result of the call void and ~ operations, which return undefined and-1.
and-,+,!, or 2*funct ...} ()。 I am afraid that the anonymous function is treated as an operand, and the same thing should be true (function () {} ()).
10.javascript has get and set accessors, and I don't know why I never saw them.
data = 1;
var o = {
Data:2,
Get Data () {
Console.log (' Get Data ');
return data;
},
Set data (value) {
Console.log (' Set data ');
data = value;
Console.log (This.data);
}
}
O.data = 99;//data and O.data will become 99
If the Data property of print O,o still displays 1 instead of 2

11.
http://www.cnblogs.com/snandy/archive/2011/03/08/1977112.html#comment_anchor_2042145

The void operator triggers the getvalue of the subsequent expression (that is, the get accessor). The grouping operator () is similar to an operator such as delete typeof. does not cause GetValue () to the operand.
Delete joke; No exception is thrown.
The reason is that when run, execute to delete joke; GetValue () is not made on identifiers-jokes.

Delete (joke);//The same does not throw an exception.
The Visible grouping operator () does not have additional work on the identifier-joke. It is only the process of affecting the formation of the syntax tree.


Above, according to "You do not know the JS" roll up P8 said, void seems to be triggered by the so-called RHS query, delete triggered the LHS query (RHS query container value, LHS query container itself)

The alert () is executed on the 12.FF in the settimeout timing, and the timer is not blocked, and on Chrome and IE11 the alert resumes.
13.delete array elements are populated with undefined, so use the [].splice bar
14.P can not contain Div, if p>div>img with $ (' P img ') will not find the element
The result of the new Date (2015,0,1) is January 1. The result of new Date (2015,0,0) is December 31, 2014.
16.mouseleave and MouseEnter are not bubbling mouseout, mouseover
17.
Target for the event object for jquery:
Relatedtarget refers to the element that the mouse will enter from within the element that listens to the event when it is in Mouseover/enter, Mouseout/leave, the element from which it enters the listener event.
Currenttarget the element that binds the event handler function.
Delegatetarget refers to the parent element of the delegate when the event delegate using JQ is used. When an event binding is not using an event delegate, it is equal to Currenttarget.
Target refers to the element that triggered the event. Target may be a currenttarget or a currenttarget child element.

About Native Event objects:

Target: The element that triggered the event
Currenttarget: The element that binds the event handler function
Originaltarget: equivalent to target
Explicitoriginaltarget: The most primitive event occurrence node, possibly a text node

18.keypress has nothing to do with KeyDown and KeyUp. It listens for character input and returns the Unicode value of the character in CharCode or keycode, and does not trigger keypress if the key is CTRL.
19.href is split with "/" and can be split with String.Split ("/").
20. Navigation bar following scrolling experience
First time: Using fixed
Find fixed based on viewport positioning, so left will be problematic, when the page has horizontal scrolling will also follow the scroll.
Second time: Using Absolute+js
The element is absolutely positioned relative to the body, and its top is set with the offset () of JQ when scrolling.
The problem is that navigation under IE and chrome can cause unexplained flicker, not a performance issue.
Third time: Using Fixed+js
The element takes a fixed, scrolling time using the JQ css () to set its left.
Head.css ({
Left: ( -1 * scrollleft | | ' auto ') + ' px '
})
When auto is used without horizontal scrolling, the value of the relative viewport to the left offset scrolls when there is a horizontal scroll.
21.$ (document). Scroll (function ...) This cannot listen for scrolling events in IE8 and should be changed to $ (window)
22.window.undefined is immutable, but functions can be defined internally undefined
23. Compare the height of the browser viewport to the body of the page
(Document.documentElement.clientHeight > Document.body.clientHeight)
23.1 Document.documentElement.scrollHeight = = = $ (document). Height ()

24. Declare an empty array arr, set arr[5] = undefined;
Then arr.length = = = 6, using for (var i in arr) {Console.log (i)}, will only print 5
25. Write this in callback, as if it turns into a undefined
26.arguments is not an array, so you cannot do arguments.slice directly ()
Have to Array.prototype.slice.call (arguments, 1)
27.var A; not equal to var a = undefined;
function f (a) {
var A;
Console.log (a)
}
F (0)//0
function f (a) {
var a = undefined;
Console.log (a)
}
F (0)//undefined
The priority order of execution is:
var A;
A = Arguments[0]
a = undefined;
27.1 What about the read priority for external variables?
var data = 1;
function f () {
var data = data;
Console.log (data)
}
F ()//print undefined.
and
var data = 1;
function f (data) {
var data = data;
Console.log (data)
}
f (data)//print 1.
Description of the external variable reading, also before a = arguments[0];
"It is also possible that the data will be read in the scope of the search, the results found in the internal scope of Var A, did not go to the outside"


28. A Elem.click () does not trigger its jump function, it must add a child element, and the child element simulates the click.
29. Event objects in the event binding,
E.delegatetarget is the parent element that is being delegated
E.currenttarget is the target child element
E.target is the element that triggers the event, that is, the child element or its child element
30.json.parse (' {"Left": 1} '), note that it must be in double quotes, $.parsejson is the same.

31. All say that for-in will traverse all the properties on the prototype chain, why does traversal of {} not traverse to the ToString key?
Https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty
Object.defineproperty ()

32. The implementation of a deep copy using a restore string is restrictive:
var o = {
A:1,
B:2,
Sum:function () {return a + B;}
};
var O2 = Json.parse (Json.stringify (o));//object {a:1, b:2}
Seems to be unable to copy the meaning of the method

And there are problems with inheritance:
Json.parse (Json.stringify (New A ())) instanceof A = = = False

33. In my opinion, all constructors must have a function name so that you can use O.constructor to see the constructor of the example O.
The 34.onblur event can be triggered on the body (click Body and click on the page outside the frame where the body is located). Points outside the page is not valid, the point frame inside the body outside the area is also invalid).
If you write <body onblur= "", unlike the onclick, the onblur triggered in input will not trigger the event handler (after all, click also points to the body, and the focus does not leave the body);
34.1 when using JQ, the DIV element cannot trigger the Blur event, but it can do a Blur event delegate for the input.
The 34.1.1 Blur event is not able to propagate events, and the principle of event delegation is to check
var a = function f () {};console.log (f)//f is not defined
F can actually become a private variable
36. Curly braces "{" Cannot begin as an expression
Http://www.cnblogs.com/ziyunfei/archive/2012/09/16/2687589.html
{} = = true//expected expression, got ' = = '
True = = {}//no error
The curly braces in 36.1 {a:2} are considered to be blocks of code, and a:2 is the correct syntax, but I don't know what to do with
PNs. ' 0 ' = = false; But (' 0 ' && 9) will pass and return 9.
Http://www.cnblogs.com/mofish/p/3402407.html
The reason is = = rule, if any value is true, convert it to 1 again, and if either value is false, convert it to 0 and then compare.
38. Whether NG or otherwise, when an element is reused, the corresponding event listener should be off
39.keypress under FF can be triggered by the arrow keys, not in IE and chrome.
40.function F (A, b) {a = 2, B = 2;console.log (arguments)};
f ();//print an empty array
F (3);//print [2]
f (3,3);//print [2,2]
Is that when the argument is empty, the modification of the parameter does not affect the arguments object.
41. If function a returns a function reference (including the return object, the object has a method defined in the function), it is important to note that a returns the internal presence of discarded data (such as an intermediate cache of operations). If so, set it to null.
Of course, it is a precaution to do as much as possible to not produce obsolete data in operations.
In addition, use the hide-and-go encapsulation scope in the function whenever possible, without allowing the returned function to access unnecessary data.
42. Only Undefined==null
The date,date of 43.js is from 1 to 31. Month and day are all starting from 0.
The. function is its own constructor
The type of the prototype of a 44.1 function is "function", but does not inherit from function, and its constructor is directly an object
var p = function.__proto__
typeof p = = = ' function '//True this should be problematic.
P instanceof Function//False
p = = = Object.prototype//True
45.for (var i in obj) {obj = {}}
For will stage a reference to the initial obj, change the point of the obj variable, and not interrupt the traversal
typeof ASD does not have an error when ASD is undefined
47. Using a variable declared by var a = 1, using delete WINDOW.A to return false without using VAR and assigning directly a variable b = 2, the implicit global variable will be deleted via delete window.b, and the result returns True
The difference between function and eval
A function can only access the global scope, and the variables in its scope cannot be accessed there.
And Eval is performed at the current scope.
49. Variable object (VO) does not include arguments, which is an abstract concept. An active object (AO) is an entity that is generated when a function is executed, including arguments.
The properties of a variable object should include the __parent__ of the parent active object, as this can be determined at compile time, and there is also __parent__ (pointing to null) in the global object.
This is not a property of the variable object, nor is the property of the active object--this with its peers, which is the property of the execution context. (execution context, containing variable objects (I think this is the active object), scope chain, this)
The scope chain is connected to a variable object.
There seems to be no active object in the global.
50. There is a difference between storing undefined in an array and default generating undefined.
function keepundefined (v) {return v = = = undefined}
var arr1 = []; ARR1[2] = 1; var arr2 = [Undefined, undefined, 1];
Console.log (Arr1.filter (keepundefined));//[]
Console.log (Arr2.filter (keepundefined));//[Undefined, undefined]
And map is strange, actually "0" in arr1 the result is false, it will still return three values. Instead of actually traversing to arr1[0] and arr1[1], if the keepundefined print is printed only once.
arr1 = new Array (3); arr1[0] = 1; Similarly, the result is [False,u,u]
Console.log (Arr1.map (keepundefined));//[Undefined, undefined, false]
51. [0] The result of participating in the operation has the following conditions
+[0]//0, Digital
0+[0]//"00", String
0-[0]//0, Digital
if ([0]) []//Through
[0] = = 0//True
[0] = = = 0//False
52.1 +-+ + +-+ 1 This formula should be understood as 1+ (...). 1), followed by the plus minus sign.
The 53.arguments and the formal parameters are associated.
There is an accuracy problem with large and decimal operations in the. js
var a = 111111111111111110000,
b = 111111;
A + b; 1.,111,111,111,111,11E,+23-bit and back-up.
55. About the priority of valueof and ToString:
Https://zhidao.baidu.com/question/1928417783204179667.html
ValueOf is biased towards arithmetic, and ToString is biased towards display.
1, when the object is converted (for example: Alert (a)), the ToString method will be called first, if not overridden ToString will call the ValueOf method, if both methods are not rewritten, but the ToString output by object.
2. The ToString method will be called first when strongly converting to a string type, and valueof is preferred when strong to a number.
3, in the case of operators, the valueof priority is higher than ToString.

document.write ({tostring:function () {return 1}, Valueof:function () {return 10}})//1 This is the first case
1+{tostring:function () {return 1}, Valueof:function () {return 10}}//11 second case

"Experience" JavaScript

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.