Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What alternateClassNames are intended for

Tags:

extjs

extjs4

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.

like image 714
shabunc Avatar asked Aug 19 '11 13:08

shabunc


People also ask

What is Classnames?

In the HTML document, the className property is used to set or return the value of an element's class attribute. Using this property, the user can change the class of an element to the desired class. Syntax: returns the className property.

What is naming convention for classes?

Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).

What is the difference between class names and method names?

While class names start with capital letters, methods should begin with a lowercase letter. Any other words you need as part of the method name will be uppercase. NO SPACES are allowed in the names! Also, since a method is an action (where the class is the blueprint), method names should be verbs.

What does className class do in Java?

It returns the Class object that represents the specified class name. This is used if you need to get the Class object. This roughly corresponds to . getClass() which returns the Class object that corresponds to the object instance.


3 Answers

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.

like image 57
jd. Avatar answered Sep 23 '22 00:09

jd.


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/

like image 38
Kiran Avatar answered Sep 20 '22 00:09

Kiran


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

like image 40
Alex G Avatar answered Sep 24 '22 00:09

Alex G