I'm working in strict mode for the first time and, what-d'ya-know, it's also the first time in ages being able to use a non strict mode property would be useful. My question here outlines the exact problem I'm having, but the solution I've worked out could be adapted to something a lot more scaleable if I still had access to arguments.callee.
Without naming the function is there any way in strict mode that I can get a reference to the function whose scope I'm currently within?
No. You have to give the function a name.My mistake, I thought of a way, see the final code block below. I don't like it, but there we are. :-)Note that the way you're giving the function a name here:
...uses a named function expression. These are notoriously unreliable (link, link) across implementations (they shouldn't be, but are), most notably in your example above, IE8 and earlier will create two completely separate function objects, assigning one of them to the
generateScale
property and referring to a different function object within the function asGS
.It's easy to fix, though:
Or if you really don't want the function to have a name (I prefer that they have names, helps my tools help me, but hey), you can use a local within that closure:
Now you have an anonymous function, but can refer to it as
GS
from within it. Again, I wouldn't recommend it, because then you can't see the function name in call stacks and such, but you did say without giving the function a name, so...Yes, but no... I'm not sure if this is the same manner of "naming" that you speak of:
http://jsfiddle.net/4y8pY/