JavaScript authoritative guide supplements (UP)

Source: Internet
Author: User
Tags switch case

First, the Language foundation

        1.javascript, only null and undefined are values that cannot have methods, and they do not have wrapped objects. typeof null = = ' object ', typeof undefined = = ' undefined '         2. In JavaScript operations, overflow returns infinity, Underflow returns 0, also That is, divisible by 0 does not error, but returns infinity. and 0/0 returns Nan.         3.NaN is special, it is not equal to any value, that is, it is impossible to judge whether X is Nan by X==nan, only by x!=x, function isNaN () is the same.         4. The value of any JavaScript can be converted to a Boolean value.         5. The original values are immutable, and their comparisons are comparisons of values, which are equal only if their values are equal. Objects are mutable, comparisons of objects are not comparisons of values, but comparisons of references, which are equal only when they refer to the same object. The         6.if statement converts undefined to false, but = = never attempts to convert the operand to a Boolean value.         7. There are three ways to change numbers to strings, tofixed () specifies decimal places, toexponential () specifies the number of digits after the decimal point in exponential notation, and toprecision () specifies the number of significant digits.         8. The object is converted to a string, the ToString () method is used first, if it does not exist or the original value is not returned, the valueof () method is called, the object is converted to a number, and the first attempt is to use the valueof () method. Do not use ToString ().         9. Variable declarations are in advance, and local variables are really assigned only when executed to the VAR statement.         10. The global variable declared by VAR differs from the implicitly declared global variable, and the variable declared by Var cannot be deleted, and the implicitly declared variable can be deleted.         11. function declaration statements and function definition expressionsThe difference is: using VAR, only the variable name in advance, but the initialization part of the variable is still in the original position, and the use of function life, the function name and function body are advanced.         12. The match operation for each case in the switch case is actually = = = rather than = =.         13. In for. In loops, all properties of an object are not traversed, but only enumerable properties, which include custom properties and methods, and inherited custom properties. Non-enumerable properties are built-in methods and properties defined by the language core.         14.return can be used alone, so the return undefined. The         15.debugger statement is used to generate a breakpoint, but it does not automatically start the debugger, and only a breakpoint is generated if the debugger is already running.   second, use strictUse Strict is an instruction and not a statement.        Strict mode restrictions: 1. Use with is prohibited.        2. All variables must be declared first, and if not declared, an exception will be thrown. 3. In strict mode, the this value in the calling function is undefined, in non-strict mode, this is the global object. This can be used to determine whether JavaScript supports strict mode: var Hasstrictmode = (function () {"Use strict" return this = = = undefined} ()) 4 In strict mode, creating a new member for a read-only attribute or non-extensible object throws an exception, and in non-strict mode, it only fails with no error. third, the object1. There are two ways to create objects, the direct amount of objects and the constructors,. Object Direct Volume:
var obj ={            "Jim",                    
Constructor creation: var o =new object () 2. Object.prototype is one of the few objects that inherit properties from the prototype, and there are not many objects with no prototypes.        3.object.create () is the method defined in ECMAscript5, which creates a new object, the first parameter is the object's prototype, and the second argument is optional, which is used to further describe the properties of the object.        var obj = object.create ({x:1,y:2});        You can create a new object without a prototype by passing in the parameter null, and the object created in this way does not inherit hot you and things, not even the underlying method.        If you want to create a plain, empty object, such as an object created through {} or New object (), you need to pass in Object.prototype. In ECMASCRIPT3, you can use the following methods to simulate Object.create ()
 functioninherit (p) {if(object.create) {returnobject.create (P); }            vart=typeofp; if(t!== ' object ' && t!== ' function '){                ThrowTypeError (); }            functionf (); F.prototype=p; return Newf (); }
4. Property queries and settings in JavaScript, only the query attribute is realized when the inheritance exists, and the setting property is independent of inheritance.        If you access a property that does not exist, it returns undefined, but if the object does not exist, it will be an error. So to interpret the existence of a property, you need to use the following method:
var len = undefined;        if(book) {            if(book.title) {                 len =book.title.length;            }        }
or var len = book && book.title&& book.title.length;        5.delete can only delete its own property and cannot delete an inherited property.        6. Use hasOwnProperty () to check if the given name is the object's own property. 7. In ECMAscript5, attribute values can be substituted with setters and getters, and properties defined by setter and getter are called accessor properties (accessor property).        It differs from the Data property. Unlike data properties, accessor properties are not writable, and if the property has both a setter and a getter method, then it is a read-write property, if it only has a setter method, it is a write-only property, read the word return undefined, if only getter,        is a read-only property. Methods for defining accessor properties:
var o = {            data:value,            get Accessor_prop (),            set  Accessor_porp (),  }  
        accessor properties can also be inherited.         8. Attribute properties, the attributes of the data attributes are value, writable, enumerable, configurable, respectively. The properties of accessors are get, set, enumerable, configurable.         You can get the property descriptor for an object-specific property by calling Object.getownpropertydescriptor (Obj,prop).         If you want to set attribute properties, you can use Object.defineproperty (obj,prop,property);        If you want to modify multiple properties at the same time, you need to use Object.defineproperties (obj,map);        9. In ECMAscript5, You can use Object.getprototypeof to query its prototype. In ECMASCRIPT3, however, there is no equivalent function, and o.contructor.prototype is used to detect the prototype of an object.         to check if an object is a prototype of another object, use the isPrototypeOf () method.         10. The class property of an object is a string that represents the type information of the object, and the ToString method can be used to get the class of the object, but many object-inherited ToString () methods are overridden. In order to invoke the correct ToString version, you need to call the Function.call () method indirectly.         function classof (o) {
if (o = = = null) {return "null";} if (o = = = undefined) {return "undefined";} return Object.prototype.toString. Call (O). Slice (8,-1);} For custom classes, there is no way to differentiate the class of an object through class properties.

12. Serialized objects, SCMASCRIPT5 provides the json.stringify and Json.parse () methods to serialize and restore objects. Functions, REGEXP, Error objects, and undefined values cannot be serialized and restored. Json.stringify can only serialize an object's own property that can be enumerated, and for an attribute that cannot be serialized, this property is omitted from the serialized output string.

Four, array1. If you omit a value from the array's direct amount, the omitted element will be assigned a value of undefined, and the direct amount of the array allows for an optional oh-ending comma, so [,] only one element, not three. 2. In a sparse array, the length property is greater than the number of elements.        If an element is removed from the array, it becomes a sparse array.        The array methods in 3.ecmascript5 include foreach (), filter (), map (), every (), some (), reduce (), reduceright (), IndexOf (), LastindexOf (). 4. Check the array type, ECMASCRIPT5, with the Array.isarray () method.        In ECMASCRIPT3, use the following method. var IsArray = Function.isarray () | | Function (o) {return typeof o = = = "Object" && Object.prototype.toString.call (o) = = = "        [Object Array] "; }; Five, function         1. function declaration statements are not true statements, and the SCMASCRIPT specification allows them to be used only as top-level statements, which can appear in global code or embedded in other functions, but not in loops, conditional judgments, Or try, catch, finally, and with statements, note that this limit is limited to functions defined in statement declarations, and function definition expressions can appear anywhere in the JavaScript code.         2. Use this to determine whether the current strict mode is:        var strict = (function () {return!this;} ());        3.this is a keyword, represents a variable, and is not a property name, and JavaScript syntax does not allow this assignment. This does not have a scope limit, and the nested function does not inherit this from the function that called it. If the nested function is called as a method, this points to the object that called it, and if the nested function is called as a function, this points to the global object or undefined (strict mode). If you want to access this value of this external function, you need to save the value of this to a variable, which is within the same scope as the intrinsic function. Arguments is similar to this.         4. If the constructor does not have formal parameters, the JavaScript constructor call is allowed to omit the argument list and the parentheses.         5. Constructors typically do not use the return keyword, and the result of the constructor expression is the value of the new object, and if the constructor shows that an object is returned, the structure of the calling constructor is the returned object. If you use return but do not return a value or return a raw value, the original value is ignored and the new object is used as the result of the call.         6. The property of the argument object callee points to the function that is currently executing, and is not allowed in ECMAScript.         7. Custom Function Properties, when a function requires a static variable to keep a value constant, the most convenient way to define a property for the Han, rather than to define a global variable, the disadvantage is that this property may be modified by someone.       &NBSp 8. The scopes associated to closures are active.         9. In a function, the number of arguments is obtained by arguments.length, and the number of parameters is obtained by the length property of the function. The difference between         10.call () and apply (), call () all arguments after the first parameter are the arguments to pass in, and apply places all the arguments to be passed in an array.         11.ECMASCRIPT5 has a bind method that binds a function to an object that can be easily implemented in ECMAScript.         function bind (f,o) {
if (f.bind) {return f.bind (o);} else {return f.apply (o, arguments);}}

In 12.ecmascript5, bind not only binds a function to an object, but also implements Curry, which, in addition to the first argument, binds its incoming bind argument to this.

13.Function () constructor, the function created does not use lexical scopes, but the compilation of the function body code is always performed by the top-level function. For example
       var scope = "global"        function Constructfunction () {                "local";                return new Function ("return scope");    Unable to replenish local scope        }        constructfunction ();        =>global  
14. All functions can be called, but not all callable objects are functions.

JavaScript authoritative guide supplements (UP)

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.