Reputation: 43
I came across this JavaScript intricacy and was struggling to find the difference. Its about JavaScript namespaces. My question is simple, one form of namespace definition looks like this:
the other one looks like this
here f refers to the full function definition like function(vars) { ....}. I know that 1 executes the body before returning the handle to the return object. But how does 2 differ from 1?
Upvotes: 1
Views: 1360
Reputation: 220036
They both accomplish the exact same thing, but Crockford recommends the second one.
I'm not sure what you mean by "namespace" though. They both create a new closure, which you can use for local variables, so I guess it's kind of like a namespace.
Upvotes: 1