EDIT
With the number of answers saying "you can do personal things!" below, I will also add this to the beginning:
I know that you can emulate private variables in closure. This is not what I am asking for. I ask, given the two examples below, where I “export” ALL from closure, what is the fundamental difference between the two examples.
Given these two methods of creating objects / methods:
var test = {}
test = (function(){
var a_method = function(print_me){
return "hello "+print_me;
}
return {print_me: a_method};
})();
test.print_me2 = function(print_me2){
return "hello "+print_me2;
}
test.print_me('world');
>>> returns "hello world"
test.print_me2('world');
>>> returns "hello world"
I understand that the first method allows you to use private variables (which, as a python developer at heart, I really do not need), but both seem pretty indifferent to me, only the first one looks “colder” (as in all big javascript people seem to do it that way), and the second way looks very skipping & eacute;
, , ?
- , ; , , .
- " , ", " , Mozilla , ", "", .