Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8029499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T00:27:20+00:00 2026-06-05T00:27:20+00:00

var User = Parse.User.extend({ // instance members }, { // types TYPE_TRAINER : 1,

  • 0
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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T00:27:22+00:00Added an answer on June 5, 2026 at 12:27 am

    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_TRAINER and TYPE_ATHLETE keys as variables to assign values via the square bracket syntax for accessing object key/value pairs:

    var a = 1;
    var b = 2;
    
    var obj = {};
    obj[a] = "a";
    obj[b] = "b";
    

    This will result in the obj object looking like this:

    
    {
      1: "a",
      2: "b"
    }
    

    So you could do something like this, to get what you want in your code:

    
    var userMethods = {
        // types
        TYPE_TRAINER : 1,
        TYPE_ATHLETE : 2
    };
    
    userMethods[userMethods.TYPE_TRAINER] = 'Trainer';
    userMethods[userMethods.TYPE_ATHLETE] = 'Athlete';
    
    var User = Parse.User.extend({
        // instance members
    }, userMethods);
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple user model: var user = Backbone.Model.extend({ initialize: function(){ this.bind(change:auth, function (){
I want to parse a Date chosen by user: var ds = 11 /
I have code like function populate...() { var user = $.storage.get(particulars); if (user) {
I have some Mongoose Models with geospacial indexes: var User = new Schema({ name
I have this code: var a:Array = [ Ramsey, Tusey, Iuser,Sephora,'user', 'reseo', 'nesey', 'sela']
Currently I have this code var App = Ember.Application.create(); App.user = Ember.Object.create({ people: customers
You have a user input string from a textbox for example var strInput =
i have this simple script: function paginateUsers(page){ get( _config_remote_host+'/users?page='+page,function(json){ json = JSON.parse(json); var _html
using (var dataContext = new realtydbEntities()) { var user = ( from aspnet_Roles rol
I am creating a user input at one of the events: var throwConnectBox =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.