This is an academic question, to clarify my understanding of JavaScript.
A function object can be assigned attributes once it is created. However, is it possible to create a function object with attributes in one step?
For example,
function someFunction(){
}
var someFunctionObject=someFunction;
someFunctionObject.attr1="attr 1";
alert(someFunctionObject.attr1); /* "attr 1"
Here the attribute is being added in the second step, after the object has been created. Is it possible to achieve this in one step?
The short answer is no. Read below for the explanation.
The end result of your code is something like:
A function definition/declaration actually does something very similar – it creates an object with the [[Construct]] property set to the actualy body of the function. But, this is just an implementation detail and you cannot access or set that [[Construct]] property separately, so you cannot define other properties in one-go (it would require additional syntax and there is none available).
But, you can set properties from inside the function, if that’s what you need. For example, this would be useful for caching: