Skip to content

Instantly share code, notes, and snippets.

@telekosmos
Last active December 16, 2015 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telekosmos/5403220 to your computer and use it in GitHub Desktop.
Save telekosmos/5403220 to your computer and use it in GitHub Desktop.
A bad example on statics in ExtJS 4
Ext.define('My.Cat', {
statics: {
speciesName: 'Cat', // My.Cat.speciesName = 'Cat'
domestic: {
is: undefined
},
// Bad: this.self is undefined if called as My.Cat.dump();
dump: function () {
var domestic = this.self.domestic.is? 'domestic': 'wild';
console.log ('class dump: '+this.self.speciesName);
}
},
constructor: function() {
console.log('constructor: '+this.self.speciesName); // dependent on 'this'
if (this.self.speciesName == 'Cat')
this.self.domestic.is = true;
},
clone: function() {
return new this.self();
},
toStr: function () {
var domestic = this.self.domestic.is? 'domestic': 'wild';
console.log (this.self.speciesName+' is '+domestic);
}
});
var cat = Ext.create('My.Cat');
console.log ('Getting static domestic...'+My.Cat.domestic.is);
cat.toStr();
// My.Cat.dump(); // bad, raises an this.self undefined error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment