I want to achieve the same as this…
var x = function(){ return "abc"}
x.y = 123
x() // "abc"
x.y // 123
but to define the properties inside the function definition like this…
var x = function(){
// declare `this.y` here somehow...
// this.y = 123
return "abc"
}
You can give functions a name even when instantiating them as part of an expression:
Unfortunately, some browsers have weird quirks in the implementation of that highly useful feature, so it’s not really completely safe to use it.
Note that in the above, there are two separate “x” symbols. The function name “x” is bound inside the function, and it hides the variable “x” in the outer scope.