JavaScript Language Essence Notes

Source: Internet
Author: User

JavaScript Language Essence notes

Mastering every feature of the language can make you pushy, but it is not recommended, because some of the features may cause more trouble than they are worth. As the book says, bad material does not carve out good work, to become a better programmer, to take its essence to the dregs. When you know what to do, it can also perform better, programming a relatively difficult thing, should not be ignorant of the state of the beginning of the programming journey.

JS in the note for//or/*content*/, note must accurately describe the code, otherwise the unused comments are worse than no comments.

The code block in JS does not create a new scope, so the variable should be defined in the head of the function, not in the code block.

The Try statement executes a block of code and captures any exceptions that the code block throws. A catch clause defines a new variable to receive the thrown exception object. The throw statement throws an exception, and if in a try, the Process Control statement jumps to the catch clause, and if the function call is discarded in the function, the control flow jumps to the catch clause of the try statement that called the function

The return statement causes the return to be returned in advance from the function, which returns the specified value, but returns undefined if not specified, and does not allow wrapping between the return keyword and the expression

Objects are passed by reference and they will never be copied.

The prototype connection does not work at the time of the update, and when we make a change to an object, we do not touch the object's prototype. It is only used when retrieving values. If we try to get a value of the object, but the object does not have this property name, it will look for the prototype object, if not in the prototype object, then from its prototype, and so on, and finally to Object.prototype. If the attribute does not exist in the prototype chain at all, the result is undefined, a process called a delegate.

Hasownprototype () detects whether an object has this property, and the method does not check the prototype chain.

The order of the in property names is indeterminate, and the best way is to avoid them altogether, and create an array to hold the property names in the correct order

The Delete delete property does not touch any object in the prototype chain, allowing the properties from the prototype chain to be revealed.

JS can arbitrarily define global variables, but it weakens the flexibility of the program and should be avoided.

Programming is the ability to break down a set of requirements into a set of functions and data structures.

A function in JS is an object, a collection of key-value pairs, and a hidden link to a prototype object. The object literal produces an object that is linked to the Object.prototype. The function object is linked to Function.prototype, and the prototype object itself is linked to object.prototype. Each function does not implicitly create two properties: the context of the function and the code that implements the function's behavior.

Each function object is created with a prototype property, its value has a constructor property and the value is the object of the function, which is completely different from the hidden link to function.prototype.

Because functions are objects, they can be used just like any other value. Functions can hold variables, objects, and arrays. Functions can be passed as arguments to other functions, functions can return functions, and methods can be owned. The difference between functions is that they can be called.

Function literals can appear in any allowed expression, functions can also be defined in other functions, an internal function in addition to access to their own parameters and variables, but also it can freely access the parent function nested inside the parameters and variables.

function objects created from function literals contain a connection to the external context, called a closure.

Calling a function suspends execution of the current function, passing control and parameters to the new function, in addition to the formal parameters defined at the time of declaration, each function has two additional parameters this and arguments

This depends on the mode of invocation, JS has a 4 call pattern: The method call function calls the constructor called the Apply call, they have a difference on the initialization of this.

The number of actual parameter arguments in JS and the number of formal parameters do not match, it will not cause a running error. If the actual parameter value is too large, it is ignored. Too little, the missing value is defined as undefined. No type checking is performed on parameter values, and any type of value can be passed to any parameter.

Method invocation Pattern

When a function is saved as a property of an object, it is called a method, and when a method is called, this is bound to the object, and if the invocation expression contains an action to extract the property, it is invoked as a method. Method can use this to access its own object, so he can take a value from the object or modify the object. This super-delay binding allows the function to be reused for this when the bind to the object occurs at the time of the call. The method through this can get the context of the object to which they belong is called a public method.

Function call pattern

When a function is not a property of an object, it is called as a function. At this point, this is bound to the global object, and the result is that the method cannot use intrinsic functions to help it work. Because this binds the wrong value, you cannot share the method's access rights to the object. Fortunately: If the method defines a variable and assigns the value to this, then the function's intrinsic function can access this through that variable, which, by convention, is named that.

Constructor mode

JS when a prototype-based language, objects can inherit properties directly from other objects. The language is not of type.

A function that, if created to be called with the new prefix, is the constructor function, which, by convention, is stored in a variable named in uppercase format. If you call the constructor function without adding new, the consequences are serious.

Apply Call pattern

The Apply method lets us construct a parameter array to pass to the calling function, allowing us to select the value of this, the Apply method receives two parameters, all one is bound to the value of this, and the second is an array of arguments.

 

  

JavaScript Language Essence Notes

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.