PDA

View Full Version : Static variable named 'name' not set



JIWAYDEF4
27 Feb 2012, 12:28 AM
Hello,
Is it normal that I can't use a static field named 'name' in my class ? (I use Ext JS 4.0.7 on Firefox)


Ext.define("MyClass", {
statics: {
myVar: "toto",
name: "could not be found"
}
});

Ext.onReady(function(){
console.log("MyClass.toto = ", MyClass.myVar);
console.log("MyClass.name = ", MyClass.name);
});


Could you explain me why the value of the variable name is not set.
Thanks in advance,

friend
27 Feb 2012, 4:45 AM
name is most likely a reserved word. Change the property name to something like testName and see what you get.

sskow200
27 Feb 2012, 7:37 AM
All defined objects have a getter function called getName() which I would assume utilizes this.name. Hence, this is not something you can override via a static property.

JIWAYDEF4
27 Feb 2012, 2:15 PM
Thanks for your answers!
@friend: yes, it works with another variable name (like testName); this is why I use a second variable named 'myVar' in my example.
@sskow200: You are right; Ext.Base has a function 'getName()'. It's not obvious to guess that implementation will impact my static variable.
A workaround which works:


Ext.ns("MyClass");
MyClass.myVar = "toto";
MyClass.name = "could not be found";

Ext.onReady(function(){
console.log("MyClass.toto = ", MyClass.myVar);
console.log("MyClass.name = ", MyClass.name);
});