I am looking for a shorter way to make a JavaScript object that can be used as a function. For instance, I can do the following:
var A=function(){window.alert('Hello World');}
A.hello='World';
Notice that I can call A() or access A.hello.
Is there a way to accomplish this using curly braces to create the object?
var A={
?:function(){window.alert('Hello World');},
hello:'World',
};
varstatement and sayfunction A() ...with effectively the same result. But as per am not i am's answer there isn't a syntax to create a function and give it properties all in one statement.