Namespace by direct assignment
antipattern 3 global variables
just 1 global variable, no function collision and more meaningful function names
When multiple modules are involved, avoid proliferating global names by creating a single global namespace. From there, any sub-modules can be added to the global namespace. (Further nesting will slow down performance and add unnecessary complexity.) Longer names can be used if name clashes are an issue:
"My name is undefined"
In the above code, person.bio makes use of the context (this). When the function is called as person.bio(), the context gets passed automatically, and so it correctly logs "My name is John Doe". When assigning the function to a variable though, it loses its context.
In non-strict mode, the default context is the global object (window). In strict mode it is undefined.
this in constructor functions
When using a function as a constructor, it has a special this binding, which refers to the newly created object: