Last active
December 16, 2015 08:08
-
-
Save telekosmos/5403220 to your computer and use it in GitHub Desktop.
A bad example on statics in ExtJS 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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