While experimenting with JavaScript, I encountered a syntax error. My attempt was to assign an object key with a value returned from a method.
var a = new function(){
this.b = function()
{
return "c";
}
};
var myobj = {
a.b:"d" //This line triggers a syntax error
};
The above snippet will generate an error message; however, surprisingly, the following code is allowed in JavaScript:
var n = a.b;
var myobj = {
n:"d" //No error thrown here
};
Even though both typeof a.b
and typeof n
indicate that they are functions?