What alternateClassNames are intended for
Asked Answered
A

3

6

So, int ExtJS we have:

  • "real" type name (that one that goes as first param in Ext.define)
  • alias
  • alternateClassName
  • xtype

The most enigmatic to me is alternateClassName. Why do we actually need them if we already have such a zoo of type descriptors? Note that I'm not trying to discuss the quality of the ideological approach. The question is only about why this was implemented and for what exactly purposes for.

Acuff answered 19/8, 2011 at 13:59 Comment(0)
C
8

They're used for backwards-compatibility. For example, Ext.grid.Panel in ExtJS 4 has

alternateClassName: ['Ext.list.ListView', 'Ext.ListView', 'Ext.grid.GridPanel']

because it replaces ListView and used to be named Ext.grid.GridPanel.

Cupo answered 20/8, 2011 at 7:5 Comment(0)
C
2

As per i know alternateClassName is helpful to call one class with diffrent names and we can use the actions as per class name.

The below code will be helpful for you:

Ext.define('Sample', {    
    alternateClassName: ['Example', 'Important'],     
    code: function(msg) {        
        alert('Sample for alternateClassName... ' + msg);     
    },
    renderTo :document.body
});
var hi = Ext.create('Sample');
hi.code('Sample');
var hello = Ext.create('Example');
hello.code('Example');
var imp = Ext.create('Important');
imp.code('Important');

In the above code,you can find the things like:

1.We are using three names called Sample,Example,Important for one class.
2.We can use the action i.e., alert message according to the class name.
3.We are displaying the alert message based on the class name.Here we are displaying the alert message for showing the result.But we can write some actions according to the class name like,if we want to create one button and we need to write action on the button as per class name then this will be helpful.

You can fint the working sample below:

http://jsfiddle.net/kesamkiran/kVbra/30/

Culicid answered 20/8, 2011 at 5:26 Comment(3)
actually, you are explaining how it works from technical point, but don't explaining, why on earth should we want to have N names of the same class.Acuff
You can reuse the code as per your wish.As per i know,For example,if toolbar and one button is there in two tabs,but i need to write the button click eent based on active tab.At that time we can use this method.Culicid
late answer but alternateClassName can be used to point to singleton functions, shorthand, so you don't have to point to the path were the singletons are defined shortening the function call invocationSimonton
M
1

alias

An alias consists of a namespace and a name concatenated by a period as [namespace].[name]

Because of the namespace, its usage is restricted to context, e.g. widget, store, controller, etc (e.g. for a controller derived class you can use an alias like "controller.foo", and you can now use only "foo" name when attaching the controller to a view)

xtype

Only applies to Ext.Component derived classes

Useful when defining views because you write less code

alternateClassName

more general purpose than above two. you can use this for your utility classes, so you don't have to reference the whole namespace

For a singleton class used for storing constants declared as app.util.navigationConstants, you can define an alternate class name that is shorter, NavConsts. And you could now use NavConsts.CONST_NAME instead of app.util.navigationConstants.CONST_NAME

Mamba answered 14/5, 2015 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.