ExtJS allows users to use Ext.define custom classes. This article will show you how to use the Ext.define custom class using an example, and describes how to use the dynamic load (require method) of ExtJS.
JavaScript Custom Classes
In JavaScript, the custom class is this:
//in JavaScript, the custom classvarperson =function(name, age) { This. Name = ""; This. Age = 0; This. Say =function(msg) {alert ( This. Name + "Says:" +msg); } This. init =function(name, age) { This. Name =name; This. Age =Age ; } This. Init (name, age);}
In this code, we define the person class, which has the name and age two properties, with the Say and init public methods. When a class is created, the initialization of the class is defined by calling the Init method (so the Init method can be thought of as the constructor of the class). Let's take a look at the usage of this class:
var New Person ("Tom", +); Tom.say ("Hello");
Run effect
We've simply introduced how to customize classes in native JavaScript, because this article focuses on the methods of customizing classes in ExtJS, so more about JavaScript custom objects, you can refer to my previous article: "Custom JavaScript Class", Let's go to the bottom of this article and see How to use the Extjs.define method to customize the class.
Custom Classes in ExtJS
In ExtJS, we also define a person class, first look at the specific code:
Using Ext.define to customize classes