/** * 1, "Object-oriented" has three basic characteristics, namely encapsulation, inheritance and polymorphism. Generally speaking, three features are fully satisfied, we call the "object-oriented language" * and the language that satisfies some of these features is: "Object-based language." * * 2, "object system" inheritance characteristics, there are three implementations, including class-based, prototype-based, and meta-class based. These three kinds of object models have their own characteristics and have their own applications. * In this, JavaScript does not use our common class inheritance system, but rather uses prototype inheritance to implement the object system. Therefore, there is no "class" in JavaScript, and a mechanism called "constructor" is used to implement some functions of the class. * 3, empty objects (null) and Empty objects * * in JavaScript, "Empty objects" is the foundation of the entire prototype inheritance system. * * 3.1), in JavaScript, an empty object (NULL) exists as a reserved word. Null represents such an object: * belongs to the object type. * The object is null. * Because it is not from the object () constructor, or its subclass instance, the instanceof operation returns false. * * 3.2), empty object * is a standard object instance constructed through object (). * For example, we use: obj = new Object () to get the obj instance. * In addition, the object's direct amount also implicitly calls object () to construct the instance, so the following code can also get an "empty object" * obj = {} * Empty object has all the properties of "object". Therefore, the predefined properties and methods (ToString, valueof, and so on) can be accessed, and the instanceof * operation returns TRUE. * * Sometimes we say empty objects are "clean objects". By default, empty objects have only predefined properties and methods. While the for...in statement cannot list these properties and methods, empty objects do not have any effect in for...in. * * *//** * The following code illustrates: Oject () constructor prototype, Objct.prototype * Objct.prototype * 1), it is an empty object * * 2), it is not from the OBJCT () constructor instance, so I The nstanceof operation returns false * * 3), there are predefined properties and methods in it * Object.prototype.toString = function () {return "";}; * * 4), obj =New Object () and obj = {} * These two ways of producing objects are actually copying an image of an "object" from the Object.prototype, so they are also "empty objects" * 5), and it has no prototype and __proto__ properties, stating It's top-notch. * * 6), new Object () is an instance of object, the instance does not have a prototype attribute, but it has a __proto__ */console.log (object.prototype) inside it; [Object Object]console.log (typeof Object.prototype); Objectconsole.log (Object.prototype = = = null); Falseconsole.log (Object.prototype instanceof Object); Falseconsole.log (Object.prototype instanceof Function); Falseconsole.log (Object.prototype.prototype); Undefinedconsole.log (object.prototype.__proro__);//undefinedconsole.log (new Object (). prototype);//undefined, Because it is an instance, there is no prototype property Console.log (New Object (). __proto__);//objectconsole.log (New Object (). __proto__.prototype);// Undefined, because it is an instance, there is no prototype property Console.log (New Object () __proto__.__proto__);//null, why is null,//take prototype object proto = object.prototype;//enumerates the object members and counts var num = 0;for (var n in Proto) {num++}//display count: 0console.log (num);/** * The following method of invocation is incorrect. Be sure to note */function Myfunca () {alert ("AA");} Myfunca.prototype = {show:function () {alert ("Show");}} Myfunca.show (); Is wrong, only new time, can write so//myfunca.prototype.show ();//show/** * Test * By the following example, we can conclude that: * If the function does not indicate what its prototype prototype is, The default is its own. * * The possible logic is: * var __proto__ = null; * Function Get_prototype () {* if (!__proto__) {* __proto__ = new MYFUNCB (); * __proto__.constructor = this; *} * Retrun __ proto__; *} */function MYFUNCB () {this.name = "ff"//alert ("BB");} Console.log (myfuncb.prototype);//myfuncbvar obj = new MYFUNCB (); Console.log (Obj.__proto);//myfuncbconsole.log (obj. __proto__.__proto);//objectconsole.log (obj.__proto__.__proto__.__proto__);//null
Summary of his own Bo asked