lundi 29 décembre 2014

EmberJS: Where to place a function for computed properties?

For some of my models I’d like to use the same computed property. But instead of writing the same function in every single model like this:



imageURL: function(){
var path = '/images/',
ext = ".jpg";
return path + this.get('shortID') + ext;
}.property('shortID')


I would like to to something like this



imageURL: function(){
return makeImageURL(this.get('shortID'));
}.property('shortID')


And have this makeImageURL function somewhere:



makeImageURL = function(shortID) {
var path = '/images/',
ext = ".jpg";
return path + shortID + ext;
}


But where? BTW I am using Ember-CLI.





Aucun commentaire:

Enregistrer un commentaire