Sencha Touch - 类系统
Sencha Touch 是一个 JavaScript 框架,具有面向对象编程的功能。Sencha Touch 类系统基于 Ext JS 4 标准。Ext 是封装 Sencha Touch 中所有类的命名空间。
在 Sencha Touch 中定义类
Ext 提供了 300 多个类,我们可以将它们用于各种功能。
Ext.define() 用于在 Sencha Touch 中定义类。
语法
Ext.define(class name, class members/properties, callback function);
类名是根据应用程序结构命名的类的名称。例如,appName.folderName.ClassName studentApp.view.StudentView。
类属性/成员定义类的行为。
回调函数是可选的。当类正确加载时,它会被调用。
Sencha Touch 类定义示例
Ext.define(studentApp.view.StudentDeatilsGrid, { name: 'StudentName, read: function(bookName){ console.log(this.name +’is reading ’bookName); } });
创建对象
与其他基于 OOPS 的语言一样,我们也可以在 Sencha Touch 中创建对象。
使用 new 关键字 − 在 Sencha Touch 中创建对象的方法
var studentObject = new student(); studentObject.read('History');
控制台输出将是 StudentName is reading history。
sencha_touch_core_concepts.html