I saw some javaScript, like Backbone-relational written in this way:
( function( undefined ) {
"use strict";
// some code
})();
My question is: When should undefined parameter be used?
Always or in special circumstances?
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.
Most of the time when you see that pattern they are ensuring that ‘undefined’ is truly undefined. See how at the bottom they don’t pass any arguments.
This is a self executing function and you can pass parameters to it.
If your code is using undefined and you need to ensure that some other javascript library doesn’t alter the meaning of undefined then you would want to use this pattern. However, this is not something that commonly occurs, it is just a safety net. For some reason in javascript ‘undefined’ can be set a value just like any other variable.