I have never seen this design pattern before, what is it doing?
(function(def){
if(typeof module!='undefined'){
module.exports=def;
}
else{
this.nut=def;
}
}( function(){
...
}() ));
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.
This is a “immediately invoked function expression”, as Ben Alman would say. The first function defined takes one argument,
def. Wrapping this function in parantheses and passing it a second function definition (also in parentheses) immediately invokes the first function, passing it the result of the second function (it is also immediately invoked) as thedefparameter.More information: http://benalman.com/news/2010/11/immediately-invoked-function-expression/