Scopes are a set of rules that determine where and how to find variables, functions, and so on (identifiers). If the purpose of the lookup is to assign a value to a variable, the LHS query is used, and if the purpose is to get the value of the variable, the RHS query is used.The assignment operator causes the LHS query to be queried. = operator or an operation that passes in a parameter when the function is called will result in an assignment of the associated scope.The JavaScript engine first c
. What's left and right? Is the left and right side of an assignment operation.The LHS query occurs when the variable appears to the left of the assignment operation, and the RHS query is executed when it appears on the right.LHS query:1. Who is the target of the assignment operation;2. The purpose of the lookup is to assign a value to the variable (= operator or an operation that passes in the parameter when the function is called).RHS query:1. Who is the source of the assignment operation;2. T
/*** Scope of closures*/FN1 (); FN1 is able to execute without error, and for functions defined by the function func_name (), it will always be initialized first.function fn1 () {Console.log ("fn1");}FN2 (); Error: FN2 is not a function/*** Use the following method to define the function, will not be executed first, if called before the definition, error.* This function is defined by first creating an area
Many developers do not think deeply about the results of a program that is not the same as expected, only to avoid using other methods to achieve the goal.One. ClosuresRegardless of the way the function is passed to the lexical scope , it holds a reference to the original definition scope, and no matter where the function is executed, the closure is generated. Reutrn a function, callback a functionIt ca
Original address: Functional-light-js
The original, Kyle Simpson-the author of You-dont-know-js
Team of translators (in no particular order): Axi, Blueken, Brucecham, Cfanlife, Dail, KYOKO-DF, L3ve, Lilins, Littlepineapple, Matildajin, Holly, Pobusama, Cherry, radish, vavd317, Vivaxy, Meng Meng, Zhouyao
About the translator:
/loop Loop statement = + block (statement block) + Scope We often need to group a series of statements together and which we often call a block.{ = a. = Amount; Console.log (amount);}This kind of standalone {:} general block was valid but was not commonly seen in Js programs. Typically, blocks is attached to some and other control statement, such as an if statement or a loop.ClosureYou can think
ObjectiveHere is a record of their own reading you don ' t know JS series of some experience, but also JavaScript a summary of their knowledge of it. High-Energy warning: the article is longer and trivial, please bring your own bench melon seeds ~Types (Type)
Variables don ' t has types, but the values of them
define keys with normal strings)You can use the point access and [] access keys, the main difference being that the point Access property name must satisfy the naming specification of the identifier, and [] can accept any form of string.There is another nuance: function fn (a) { //undefined //1 } var obj = { 1, } fn (' ab ');When accessing a property name as a parameter into a function, use [] access to get the result correctly.In an object, the property name
for the concept of the prototype chain we usually call.According to the standard, __proto__ is not public, that is, a private property, but the engine of Firefox exposes him to become a common attribute, we can access and set up externally.The first piece of code is very simple, I believe everyone has written this, so let's see why Childfoo can access Foo's sayhi.First var childfoo=new foo (); Childfoo.__proto__=foo.prototype can be derived. So when we call Childfoo.sayhi (), there is no sayhi
is set.var myObject = { get a () { return 2; = 3; myobject.a; // 2Since we have only defined a getter, the set operation ignores the assignment operation and does not throw an error when setting the value of a.Even with a legitimate setter, the getter we define will only return 2. So the set operation has no meaning.10, the existence ofWe can judge whether this property exists in an object without accessing the value of the propertyvar myObject = { A:2};( in myObject); true in MyObject
1, the class is a design pattern, many languages provide for the class-oriented software design of the native syntax, JS also has a similar syntax, but it is completely different from the classes in other languages.2. Class means copy3. JS does not automatically create a copy of the object as if it were a class.4, in the case of inheritance or instantiation, JS o
add variable is already defined when the code is run.However, since the assignment statement executes only at run time, the value of sum defaults to undefined before the corresponding code executes.In the above example, the function expression will be an error. The function declaration parser is first read and made available before any code is executed;For a function expression, you must wait until the parser executes to the line of code where it is located before it is actually parsed for exe
Recently in writing a small JS, think of n times, also changed n times, later do not know why, the effect on the realization, and then re-read the code, exclaimed: This is the original.So do you think this code is written by yourself?I think so, and I think it's not.The reason: The program itself is through their own continuous and slowly groping, from the wrong to come out;Not the reason: The program was n
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.