Web pick-up reading notes----JavaScript language essence

Source: Internet
Author: User
Tags bitwise operators

Original link:Http://www.cnblogs.com/Cohlint/archive/2012/11/26/2788790.html 1.6 values will be false (==false), respectively, false,null,undefined, ', 0,nan 2.typeof has 6 values, which are ' number ', ' String ', ' Boolean ', ' undefined ', ' function ', ' object ', where typeof (null), the result is ' object ' 3.The number type is always 64-bit floating-point number, and a non-integer result may occur when dividing two integers 4.If the value of the first operand is false, then the operator && produces the value of its first operand. Otherwise, it produces the value of the second operand. For example, you can use the && operator to avoid retrieving exceptions caused by undefined
flight.equipment//undefinedflight.equipment.model Throw "TypeError" flight.equipment && flight.equipment.model//undefined
5.If the value of the first operand is true, then the operator | | The value that produces its first operand. Otherwise, it produces the value of the second operand. For example, you can use | | operator to populate the default value var status = Flight.status | | "Unkonwn" 6.Objects are passed by reference and will never be copied 7.When we make a change to an object's properties, we do not touch the prototype of that object. Prototype chain only when the search is worth it, it will be down to the top, until the Object.prototype to find, to use, and then stop looking, there is no return to undefined, This process is called a delegate. The hasOwnProperty method detects the unique properties that an object has. 8.The object properties that are iterated through the for-in statement contain the attributes on their prototype chain, and are unordered, and the properties that are iterated over the length of the object by the For statement contain only the unique attributes, and the order 9.Delete can delete properties of an object without touching properties on the object's prototype 10. Functions are also objects, object literals produce objects that have hidden links to Object.prototype, and function objects have to Function.prototype (the prototype object itself is linked to Object.prototype) Hidden links. Each function object is created with a prototype property whose value is an object that has the constructor property and the value is the function One by one .Each function is created with two additional hidden properties: the context (callable) of the function and the code that implements the function's behavior; Calling a function suspends the current execution, passing control and parameters to the new function. In addition to the formal parameters defined at the time of declaration, each function receives two additional parameters: this and arguments, Arguments.callee represents the function itself, typically used for recursion 12. The value of this parameter depends on the mode of the call, there are four modes of invocation in javascript: method Invocation Pattern:When a function is saved as a property of an object, we call it a method, and when a method is called, this binds to the object (as long as the function is called with a. dot or [subscript] subscript, then it is called as a method) function call Pattern:When a function is not a property of an object, then it is called as a function, this is bound to the global object, and the internal function's this is pointed to the global design flaw, which can be that=this in the external Var, as in the browser, this = window; This = globe constructor invocation mode:If you call with new in front of a function, you will create a new object that hides the prototype member linked to the function, and this will be bound to the new object. Apply Call Mode:This binds to the first argument, which is the incoming object .There is no error when the number of arguments for the function (arguments) and the type parameter (parameters) does not match; If the arguments are too many, the exceeded will be ignored. If the argument is too small, the missing is passed into the undefined. 14.arguments is not a real array, it is just an array-like object, except for the length property, which is missing other array methods. 14.5A function always returns a value without specifying a return value, which returns undefined. If the function is called in new mode and the return value is not an object, this is returned (the new object) A .JavaScript is missing block-level scopes,Therefore, it is best to declare variables that may be used in functions at the top of the function body 16. Using ClosuresTo return an external function variable, you can avoid a function being added with new to use closures: var quo = function (status) {return {get_status:function (                    ) {return status;              }               };        };   var myquo = Quo ("Amazed");        Constructor: var Quo = function (status) {This.status =status;        }; var myquo = new Quo ("Amazed"); 17. A closed-bag pitvar add_the_handles = function (nodes) {var i;          for (i = 0;i < nodes.length; i+= 1) {Nodes[i].onclick = function (e) {alert (i); The purpose of the}};add_the_handles function is to give each time processor a unique value (i). It failed to achieve the purpose because the event handler function binds the variable i, not the value of the variable I at the time the function was constructed. Correction for the following wording can be achieved: Var Add_the_handl    es = function (nodes) {var i;            for (i = 0;i < nodes.length; i+= 1) {Nodes[i].onclick = function (tempi) {return function (e) {          alert (tempi);        };     } (i); }}; 18. CallbacksSimulates an asynchronous request to prevent the client from being blocked by request = Prepare_the_request (); send_request_asynchronously (request,function (response) {display (response);}; 19. Module(module) is created through functions and closures, exposing only the available public methods, other methods are all hidden, if you do not need to pass parameters or some special harsh requirements, we can add a parenthesis after the last} to achieve the purpose of self-execution,       This instance will only have one copy in memory. The singleton mode can be implemented by module mode var Themodule = (function () {var i = 10;          return {result:function (x) {return x*i; }      };} ()); Call: Themodule.result (5); 20. Universal Recursive memory function,Adding a memory parameter can reduce the number of recursive function calls and significantly improve the efficiency var Memoizer = function (memo,fundamental) {
var shell = function (n) {
var result = Memo[n];
if (typeof result!== ' number ') {
Result = Fundamental (shell,n);
Memo[n] = result;
}
return result;
};
return shell;
}; Call: var Fibonacci = Memoizer ([0,1],function (Shell,n) {
return Shell (n-1) +shell (n-2);}); Console.log (Fibonacci (10)); .When a function object is created, the function object produced by the functions constructor runs similar code: This.prototype = {Constructor:this}; All constructor functions are named as uppercase letters, but a better alternative is not applicable to the new 22. Constructor function to accept a large list of parameters: no suggested notation: var myObject = maker (f,l,m,c,s); Suggested notation: var myObject = Maker ({first:f, last:l, State:s, city : c}); The advantage is that multiple parameters can be sorted arbitrarily, and if there are default values, you can omit some parameters and the code is easier to read .In a purely prototype pattern, we discard the class and focus instead on the object, and a new object can inherit a property of the object A .In pseudo-class mode and module mode, try to choose the latter, functional constructor Pseudo-code templatevar constructor = function (spec, my) {var that, other private instance variables; my = My | |    {}; Add shared variables and functions to my that = a new object added to that privileged method return that; .An array of JavaScript is an object that has some class array attributes. It transforms the subscript of an array into a string, using it as a property, with an attribute that can be used as an integer property name over a normal attribute. and inherit from Array.prototype, more than one length attribute; JavaScript elements of the same array can be of mixed type and have no upper bounds. 16Mvar numbers = [' zero ', ' one ', ' both '];  Numbers[numbers.length] = ' three '; Equivalent to Numbers.push (' three '); 27. Whether array detectionvar Is_array = function (value) {return value && typeof value = = = ' object ' && typeof value.length = = = ' number ' && typeof value.splice = = = ' function ' &&! (value.propertyisenumerable (' length '));}; the dross in 28.javascriptGlobal variables: Fewer and better scopes: no block-level scopes, declare all variables in the beginning of each function to automatically insert semicolons: So the brace style needs to use the Egyptian brackets unicode:javascript character is 16 bits, can only cover 65,535 words              parseint: Add the second parameter, explicit binary, parseint ("08", 10) floating point number: binary floating-point number cannot correctly handle decimal decimals, 0.1+0.2 is not equal to 0.3, but the integer part is the exact Nan  : typeof NaN = = = ' number '//true; Nan = = = Nan//false; object: JavaScript objects never have a real empty object because of the existence of a prototype chain the chicken in the 29.javascriptoperator = = and! =: will attempt to force conversions to determine the type of the value, rule complex with statement: Possible ambiguity and affect processor speed eval: reduced security, increased reading complexity continue: Refactoring Remove cont           Improved performance after Inue + +-: Make code more cryptic bitwise operators: JavaScript does not have integer types, bit operators convert their operands to integers first, then perform operations, then convert back, very slow function : Do not use function in an if statement, try to use var func = function ... Form declaration NEW: A better coping strategy is simply not to use newvoid: it will return undefined, it's useless, and confusing.

Summary: This book only more than 100 pages, priced up to 49, the first feeling is more expensive, after reading to appreciate the value for money, concentrated is the essence, almost all dry, even the appendix is dry. Read the book after reading a JavaScript primer, Very conducive to the precipitation of knowledge.

Web pick-up reading notes----JavaScript language essence

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.