Maintainable code means: a consistent, readable, predictable look that looks like the same person writing a recorded named function expression (function fn () {}) He is the expression because the parentheses () are a grouping operator whose interior can only contain the expression eval (' (' + JSON + ') ' JSON strings are usually enclosed in parentheses, Causes the parser to force the JSON curly braces to parse into an expression instead of the code block JavaScript core 1. The object Objectobject is a collection of properties and has a separate prototype object [prototype object]. This prototype object [prototype-object] can be either an object or a null value. 2. Prototype chain __proto__ The prototype chain is a finite object chain consisting of objects used to implement inheritance and shared properties. var a = {x:10, calculate:function (z) {return this.x + This.y + z}}; var B = {y:20, __proto__: a}; var c = {y:30, __proto__: a}; Call the inherited method B.calculate (30); 603. The constructor constructor automatically sets up the prototype object for the new object (prototype object) that was created. The prototype object is stored in the Constructorfunction.prototype property. constructor function fn (y) {this.y = y;} The inheritance attribute "x" foo.prototype.x = 10;var B = new Foo; b.__proto__ = = = Fn.prototype; true//"Fn.prototype" automatically creates a special attribute "constructor" and points to B's constructor itself b.constructor = = = fn; Truefn.prototype.constructor = = = FN//true4. Execution context var a = function (e) {return {//expose members exposed ADD:FUNCT Ion (x, y) {}};} Call: ar o = new A (' E '); O.add (2, 2); Reference global variable (function ($) {call: $} (JQuery)), var o = (function ($) {var my = {name = ' sn '}return my;}) (jQuery); Call: O.name extended var o = (function (my) {my.add = function () {}; return my;} (obj)); Loosely coupled extended var o = O | | {}; var o = (function (my) {return my;} (JQuery | | {})); Cloning and inheriting var o = (function (old) {var my = {},key; For (Key-in-old) {if (Old.hasownproperty (key)) {My[key] = Old[key]; }} return my;} (obj)); Sub-module Obj.sub = (function () {var my = {}; return my;} ());
function syntax if (typeof Function.prototype.method!== "function") { Function.prototype.method = function (name, call) { This.prototype[name] = call; return this; };} Extension object var fn = function (name) {
JavaScript Advanced Grammar Learning