02/26apply (parameter array), call (argument must be enumerated), bind three are used to change the function of the This object point; the first parameter of apply, call, Bind is the object that this is to point to, that is, the context to which you want to specify; apply, Call, bind three can use subsequent parameters, bind is to return the corresponding function, easy to call later; apply, invoke is called immediately. 02/27anonymous function: In the stack trace does not display the meaningful function name, is difficult to debug, does not have the function name not to refer to itself, lacks the readability and the understandable nature. Block-level scope: with, try{} catch () {}, let, Const. Let: there is no variable promotion. 02/28The execution of JS code is divided into two stages: compile stage, execution phase. all declarations that contain functions and variables are processed first before any code is executed, the declaration itself is promoted, and the assignment or other running logic is left in place. Function declarations differ from function expressions in that the function expression does not ascend as a whole, only the variable declaration that is assigned to the expression is promoted, and the function expression is left in its original position. both the function declaration and the variable declaration are promoted, but a notable detail (this detail can be found in the code that now has multiple "repeating" declarations) is that the function is first promoted and then the variable. 03/01closures allow a function to continue to access the lexical scope at the time of definition. Regardless of the means by which an intrinsic function is passed to the lexical scope where it resides, it holds a reference to the original definition scope, and the closure is used wherever the function is executed. for (var i=1; i<=5; i++) {(function (j) {SetTimeout (function timer () {console.log (j);}, j*1000);}) (i); } using Iife within an iteration will generate a new scope for each iteration, allowing the callback of the deferred function to enclose the new scope within each iteration, and each iteration will contain a variable with the correct value for us to access. for (let I=1; i<=5; i++) {setTimeout (function timer () {console.log (i);}, i*1000);} 03/02The module has two main features: (1) A wrapper function is called to create the internal scope, and (2) The return value of the wrapper function must include at least one reference to the intrinsic function, which creates a closure that covers the entire wrapper function's inner scope. The main difference: Lexical scopes are determined when writing code or definition, while dynamic scopes are determined at run time. (This is also!) The lexical scope focuses on where the function is declared, and the dynamic scope concerns where the function is called from. Dynamic scopes do not care about how functions and scopes are declared and where they are declared, only about where they are called from. In other words, the scope chain is based on the call stack, not the scope nesting in the code. 03/03the arrow function in ES6 does not use the four standard binding rules, but rather determines this based on the current lexical scope, specifically, the arrow function inherits the this binding of the outer function call (whatever the this binds to). This is actually the same as the Self = This mechanism in the code before ES6. Simply put, the arrow function is completely inconsistent with the behavior of this binding and the normal function. It discards all normal this binding rules and instead overwrites the value of this with the current lexical scope. 03/04It is important to be clear that this does not point to the lexical scope of the function in any case. Inside JavaScript, scopes are really like objects, and the visible identifier is its property. But the scope "object" cannot be accessed through JavaScript code, it exists inside the JavaScript engine. As we said before, this is bound at run time, not at the time of writing, and its context depends on the various conditions when the function is called. The binding of this and the position of the function declaration have no relation, only depends on how the function is called. This does not point either to the function itself nor to the lexical scope of the function, which is actually the binding that occurs when the function is called, and what it points to depends entirely on where the function is called. 03/06object.create (NULL) is similar to {}, but does not create an Object. Prototype this delegate, so it is more empty than {}. typeof null = = "Object": the principle is that different objects are represented as binary at the bottom, and in JavaScript the first three bits of the binary are 0, then the null binary representation is all 0, and the first three bits are 0, Therefore, "Object" is returned when TypeOf is executed. 03/07If you try to add a property to an array, but the property name "looks" like a number, it becomes a numeric subscript (so it modifies the contents of the array instead of adding a property). for objects that have JSON security (that is, can be serialized into a JSON string and can parse an object with exactly the same structure and value based on the string), there is a clever way to copy it: var newObj = Json.parse ( Json.stringify (someobj)); Note that there is a small exception: even if the property is Configurable:false, we can change the state of writable from true to false, but cannot be changed from false to true. invariance:1. Object constants: Combined with Writable:false and configurable:false, you can create a true constant attribute (not modifiable, redefined, or deleted). 2. Prohibit extensions you can use object.prevent Extensions (..) if you want to disallow an object from adding new properties and retain existing attributes. 3. Sealed object.seal (..) creates a "sealed" object that actually calls Object.preventextensions (..) on an existing object and marks all existing properties as configurable: False 4. Freezing Object.freeze (..) creates a frozen object that actually calls Object.seal (..) on an existing object and marks all the data access properties as Writable:false so that their values cannot be modified. in ES5, the getter and setter sections can be used to override the default action, but only on a single property and cannot be applied across the entire object. A getter is a hidden function that is called when a property value is obtained. The setter is also a hidden function that is called when the property value is set. 03/08"Enumerable" is equivalent to "can appear in the traversal of object properties." A tougher way to judge: Object.prototype.hasOwnProperty Call (MyObject, "a"), which borrows the underlying hasOwnProperty (..) method and binds it explicitly to MyObject On propertyisenumerable (..) checks whether the given property name exists directly in the object (not on the prototype chain) and satisfies the enumerable:true. Object.keys (..) Returns an array containing all the enumerable properties, Object.getownpropertynames (..) returns an array containing all the attributes, regardless of whether they are enumerable. traversing array subscripts takes the numeric order (for loops or other iterators), but the order in which the object properties are traversed is indeterminate and may not be the same in different JavaScript engines. Therefore, when you need to ensure consistency in different environments, be sure not to trust any of the observed sequences, which are unreliable. 03/09Use for: In traversing an object is similar to finding [[Prototype]] chains, any property that can be accessed through the prototype chain (and is enumerable) is enumerated. When you use the In operator to check whether a property exists in an object, you also find the entire prototype chain of the object, whether or not the property is enumerable. Therefore, when you look through the various syntaxes for property lookups, you look for [[Prototype]] chains until you find the property or find the complete chain of prototypes. all normal [[Prototype]] chains will eventually point to the built-in Object.prototype. Since all "normal" (built-in, not-specific extensions) objects are "originated" (or set to the top of the [[Prototype]] chain) This Object.prototype object, it contains many of the common features of JavaScript. if Foo does not exist directly in MyObject but is present in the upper layer of the prototype chain, there are three cases where Myobject.foo = "Bar" appears:1. If there is a normal data access property named Foo on top of the [[Prototype]] chain and is not marked as read-only (Writable:false), a new property named Foo is added directly to the MyObject, which is the masking property. 2. If Foo is present at the top of the [[Prototype]] chain, but it is marked as read-only (Writable:false), you cannot modify an existing attribute or create a masking property on MyObject. If you run in strict mode, the code throws an error. Otherwise, this assignment statement is ignored. In summary, no masking will occur. 3. If Foo is present at the top of the [[Prototype]] chain and it is a setter (see Chapter 3rd), then the setter will be invoked. Foo will not be added (or masked) to MyObject, nor will it redefine the setter of Foo. If you want to block Foo in both the second and third cases, you cannot use the = operator to assign a value, but instead use the Object.defineproperty (..) To add Foo to MyObject. 03/10Foo.prototype Default has a public and non-enumerable property. Constructor, this property refers to the function that the object is associated with. You can see that the object created by calling new Foo () through the constructor also has a. Constructor property, which points to "create this object's function." This function call becomes a "constructor call" after the normal function call is preceded by the new keyword. In fact, new will hijack all ordinary functions and invoke it in the form of a constructed object. In other words, the most accurate explanation for "constructors" in JavaScript is that all function calls with new. This is a very unfortunate misunderstanding. In fact, the. Constructor reference is also delegated to Foo.prototype, and Foo.prototype.constructor is the default point to Foo. Foo.prototype. Constructor property is just the default property of the Foo function at the time of declaration. If you create a new object and replace the default. prototype object reference for the function, the new object is not automatically obtained. Constructor property. function Foo () {/*.. * *}Foo.prototype = {/*.. */};//Create a new prototype objectvar a1 = new Foo ();A1.constructor = = = Foo;//false!A1.constructor = = = Object;//true!delegate to the Object.prototype at the top of the chain of delegates. This object has the. Constructor property, which points to the built-in object (..) function. Bar.prototype = object.create (Foo.prototype). If you use the built-in. bind (..) function to generate a hard-bound function, the function is not. Prototype property. Using instanceof on such a function, the. prototype of the target function will replace the. prototype of the hard-bound function. Foo.prototype.isPrototypeOf (a);b.isprototypeof (c);. __proto__ does not actually exist in the object you are using, it exists in the built-in Object.prototype (it is not enumerable). 03/11object.create (NULL) creates an object with an empty (or null) [[Prototype]] link, which cannot be delegated. These special empty [[Prototype]] objects are often referred to as "dictionaries", which are completely free of interference from the prototype chain and are therefore ideal for storing data. The link to the object is referred to as the "prototype chain", and the essence of the mechanism in JavaScript is the association between objects. delegate behavior means that certain objects (XYZ) delegate this request to another object (Task) When a property or method reference is not found. object affinity can better support the separation of concerns (separation of concerns) principle, and creation and initialization do not need to be merged into one step. //Let Foo and Bar relate to each otherfoo.isprototypeof (Bar);//Trueobject.getprototypeof (Bar) = = = Foo;//TrueThe behavior delegate considers that the objects are sibling relationships and are entrusted to each other, rather than to the parent class and the child class. JavaScript's [[Prototype]] mechanism is essentially a behavior delegation mechanism. In other words, we can choose to implement the class mechanism in JavaScript, or we can embrace a more natural [[Prototype]] delegation mechanism. object Affinity (objects are previously interrelated) is a coding style that advocates creating and correlating objects directly without abstracting them into classes. Object associations can be implemented very naturally with behavior delegates based on [[Prototype]]. first, you might think that ES6 's class syntax introduces a new "class" mechanism to JavaScript, not really. Class is basically just the existing [[[Prototype]] (delegate!). ) mechanism of a syntactic sugar. That is, class does not statically replicate all behaviors at the time of declaration, just like a traditional class-oriented language. The class syntax cannot define the classes member properties (only methods can be defined). Class syntax is still subject to accidental masking. Class is well disguised as a solution for class and inheritance design patterns in JavaScript, but it actually backfired: it hides many problems and brings more small but dangerous problems.
Wen Xin--javascript book pick (i.)