views:

122

answers:

4

Hi all,

I'm using javascript and have this enumeration:

filterType = { Campaign : 'Campaign', Class : 'Class', Date : 'Date', 
               DateGeq : 'DateGeq', DateLeq : 'DateLeq', 
               DateRange : 'DateRange', Status : 'Status' }

I'd like to name it as:

Filter.filterType = { Campaign : 'Campaign', Class : 'Class', Date : 'Date', 
                      DateGeq : 'DateGeq', DateLeq : 'DateLeq', 
                      DateRange : 'DateRange', Status : 'Status' }

The interpreter doesn't like dot character.

Can I add a dot character in enumeration names???

Thanks!!!

+5  A: 

You're probably getting an error because you're trying to assign a value to the filterType member on a class called Filter, but Filter is undefined. It'll work if you defined Filter first.

var Filter = {};

To do it all in one line you could write:

var Filter = { filterType: { ... } };
David Hedlund
Just to nitpick, there's no class in javascript. Filter is an Object.
Alsciende
Thanks for your answer.
jaloplo
quite right, Alsciende, thanks for remarking
David Hedlund
There's also no enumerations
Justin Johnson
+1  A: 

How about doing like this?

Filter={}

Filter.filterType = { Campaign : 'Campaign', Class : 'Class', Date : 'Date', 
                      DateGeq : 'DateGeq', DateLeq : 'DateLeq', 
                      DateRange : 'DateRange', Status : 'Status' }
S.Mark
Thanks for your answer.
jaloplo
+2  A: 

I guess you have "Filter" is undefined.

var Filter ={};
Filter.filterType = {....}
Dennis Cheung
Thanks for your answer.
jaloplo
A: 

There are no enumerations in JavaScript. What you have shown here is an object, more specifically, an object literal constructed using JSON notation.

You're second example is attempting to create a filterType property (which is a redundant name, by the way) on an object named Filter. If Filter doesn't exist, it will cause an error (consider it analogous to null.filterType which obviously doesn't make any sense). You must first define Filter.

To define Filter and Filter.filterType in one expression, you can use the following notation:

var Filter = {
    filterType: {
        Campaign : 'Campaign', Class : 'Class', Date : 'Date', 
        DateGeq : 'DateGeq', DateLeq : 'DateLeq', 
        DateRange : 'DateRange', Status : 'Status'
    }
};
Justin Johnson