8 ms·
At 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 t
by Jach 15y ago
At 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.