Extjs4 定義及繼承類

ExtJs4使用Ext.define來定義類:

( String className, Object data, [Function createdFn] ) : Ext.Base

Ext.define and Ext.ClassManager.create are almost aliasesof each other, with the only exception that Ext.define allows definition of overrides.To avoid trouble, always use Ext.define.

Ext.define('My.awesome.Class', {
    someProperty: 'something',
    someMethod: function() { ... }
    ...

}, function() {
    alert('Created!');
    alert(this === My.awesome.Class); // alerts true

    var myInstance = new this();
});

Parameters

  • className : String

    The class name to create in string dot-namespaced format, for example:My.very.awesome.Class, FeedViewer.plugin.CoolPager. It is highly recommended to follow this simple convention:

    • The root and the class name are 'CamelCased'
    • Everything else is lower-cased
  • data : Object

    The key-value pairs of properties to apply to this class. Property names can be of any validstrings, except those in the reserved list below:

  • createdFn : Function (optional)

    callback to execute after the class is created, the execution scope of which(this) will be the newly created class itself.

這個方法可以通過extend屬性來繼承類:

Ext.define('Person', {
    say: function(text) { alert(text); }
});

Ext.define('Developer', {
    extend: 'Person',
    say: function(text) { this.callParent(["print "+text]); }
});

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章