Reputation: 923
I'm trying to pass an enum to a function, but keep getting an 'undefined' error.
If I try this:
var myVar = new myFunc('{ first:1, second:2 }')
and then
function myFunc(enum) {
var myEnum = enum;
}
I find that myEnum
is defined as { first:1, second:2 }
but myEnum.second
is undefined.
If I hard-code the same values directly into the myEnum =
it works.
I also tried putting the braces on the myEnum =
line instead, but no change.
What am I doing wrong? Have I simply passed a string to myEnum
?
If so, how can I ensure that myEnum
is indeed an enum?
Upvotes: 1
Views: 2961
Reputation: 6796
here you are using string as you have bounded the object inside quotes '
var myVar = new myFunc('{ first:1, second:2 }')
myEnum.second
means you are trying to access the the second
property of the myEnum
referrenced object, which is not, as you have used quotes '
around
use
var myVar = new myFunc({ first:1, second:2 })
Upvotes: 1