3 ms·
We have to name javascript functions twice? We should be using eval to get the global object? If you are going to go through that hassle to get the global obj
by sixcorners 15y ago
We have to name javascript functions twice?
We should be using eval to get the global object?
If you are going to go through that hassle to get the global object why not do the same for everything else you will ever use? Every single external variable could have it's own privately named identifier. Won't that be fun.
- omgtehlion 15y agoAnd you didn’t get to “Design Patterns” yet. You’ll be surprised.
- Jach 15y agoAt first I thought the naming-twice thing (which I've never done or seen) was similar to the C idiom of doubly naming your typedef structs so users don't have to type `struct Foo` everywhere if they don't want to. I was envisioning a useful application with Node where you might say `exports.foo = function foo() { };` so you can call `foo();` instead of `exports.foo();` in the same code file, but that doesn't seem to work when I tried it and so this "pattern" is useless in that context. (Meaning I'm back to `function foo() { }` and then `exports.foo = foo;`.)
- dspeyer 15y agoexports.foo = function foo() { }; is indeed where you might use this. It doesn't let you call it as foo(), though. What it does is make exports.foo.toString() include "foo". This can be useful for debugging, and possibly other things.