The Practical Module pattern accepts this as a global:
(function( global )
var Module = ...
...
...
global.Module = Module;
})( this );
What’s the rational behind this decision?
The same goes for the Practical Constructor.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The code that you quote is technically equivalent to:
and if it’s used as intended, outside of a constructor or method, then
thiswill refer to the global object (such aswindow). By using the nameglobalinstead ofthisto refer to it, the code makes it more explicit that this is what’s happening. (You have to admit, “global” is a clearer name for the global object than “this“!)