用extjs4.2语法定义一个类
我正在尝试学习ExtJS4.2,在定义类和创建对象时,在语法和跟踪方面,我确实需要一些帮助。需要帮忙吗用extjs4.2语法定义一个类,extjs,Extjs,我正在尝试学习ExtJS4.2,在定义类和创建对象时,在语法和跟踪方面,我确实需要一些帮助。需要帮忙吗 Ext.define('Student', { name: 'unnamed', getName: function() { alert('Student name is ' + this.name); }, constructor: function(studentName) { if (studentName) this.na
Ext.define('Student', {
name: 'unnamed',
getName: function() {
alert('Student name is ' + this.name);
},
constructor: function(studentName) {
if (studentName) this.name = studentName;
},
statics: {
staticMethod: function() {
alert("This is static method of student class");
}
}
}
);
//create an object using 'new'
var student1 = new Student('ABC');
student1.getName();
//create an object using Ext.create
var student2 = Ext.create('Student', 'XYZ');
student2.getName();
//create an object using className.create()
var student3 = Student.create('123');
student3.getName();
//call static method by className.staticMethodName()
Student.staticMethod();
对代码进行一些注释,以便您更好地理解:
// Class Student definition
Ext.define('Student', {
name: 'unnamed', // a basic string property
getName: function() { // a basic function to display a message with the name
alert('Student name is ' + this.name);
},
constructor: function(studentName) { // The constructor function with the name of the student as parameter
if (studentName) this.name = studentName; // If the name is given then assign it to the instance
},
statics: { // Begin of static functions declaration
staticMethod: function() { // a static function called "staticMethod"
alert("This is static method of student class");
}
} // End of static functions declaration
});
// End of class definition
//create an object using 'new' with the name "ABC"
var student1 = new Student('ABC');
student1.getName(); // Should display a message alert with text: "Student name is ABC"
//create an object using Ext.create
var student2 = Ext.create('Student', 'XYZ'); // The second parameter should be ignored
student2.getName(); // Should display a message alert with text: "Student name is Student"
//create an object using className.create()
var student3 = Student.create('123');
student3.getName(); // Should display a message alert with text: "Student name is 123"
//call static method by className.staticMethodName()
Student.staticMethod(); // call the static function declared in Student.
// This does not need any class instance
你现在的问题不是很清楚。你要问的代码是什么?@Evantimboli这不是我的代码,这是一个示例代码,我正在寻求帮助,如果可能有人可以跟踪我这个示例代码。我将不胜感激。因为我对这个概念有一个大致的概念,但是我想深入了解代码的细节,所以我会确保我完全理解它。