JavaScript Advanced Grammar Learning

Source: Internet
Author: User

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

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.