8, the Ext.js writing class way
This is used in the Ext core3.0,ext ext.extend to define a class (of course it is more to extend a class), ext the entire framework of various controls such as Panel,messagebox are used to extend the Ext.extend method. This is only used to define a simplest class.
As you can see from the Ext.extend code, it still uses constructors and prototypes to assemble a class.
Only two parameters can be passed here, the first argument is the root class object and the second is the prototype.
Copy Code code as follows:
/**
* Person Class
* @param {Object} name
*/
var person = ext.extend (object,{
Constructor:function (name) {this.name = name;},
Setname:function (name) {this.name = name;},
Getname:function () {return this.name;}
});
Create an Object
var p = new Person ("Lily");
Console.log (P.getname ());//lily
P.setname ("Andy");
Console.log (P.getname ());//andy
Test whether instanceof and P.constructor correctly point to Person
Console.log (P instanceof person);//true
Console.log (P.constructor = = person);//true
More specifically, if you simply define a class, the first argument will always pass object.