var User = Parse.User.extend({
// instance members
}, {
// types
TYPE_TRAINER : 1,
TYPE_ATHLETE : 2,
types: {
TYPE_TRAINER : 'Trainer',
TYPE_ATHLETE : 'Athlete'
}
});
I want to have TYPE_TRAINER and TYPE_ATHLETE maintain the values of 1 and 2 as defined prior to the types object so that I can use the types object in a template.
If you don’t know about Parse, Parse.User is an extension of Backbone.Model.
Thanks!
What you’re asking is not directly possible in JavaScript object literals. Object literals are always a literal value on the left hand / key side.
The closest you could get is to use the
TYPE_TRAINERandTYPE_ATHLETEkeys as variables to assign values via the square bracket syntax for accessing object key/value pairs:This will result in the
objobject looking like this:So you could do something like this, to get what you want in your code:
It’s more code than you probably want, but it’s the only way to achieve what you want because of the object literal syntax.