So, I came across an answer, but this is not enough to expand my knowledge base.
I was looking for age, which means x = x || y, z x = x || y, z in stackoverflow
I found this. What is the construction x = x || y mean?
But the problem is, what is , z for?
I often see these expressions window.something = window.something || {}, jQuery window.something = window.something || {}, jQuery
I already know that if false was returned in the first argument, then {} will be assigned to the something property.
My question is: what is , jQuery for?
Can someone enlighten me and rob me of this very important knowledge?
UPDATE 11/11/2014
So, I tried to do the tests.
var w = 0, x = 1,y = 2,z = 3; var foo = w || x || y, z;
and this is the same as this.
var w = 0, x = 1,y = 2; var z = function(){return console.log("this is z");} var foo = w || x || y, z;
other.
var w = 0, x = 1,y = 2; var z = function(){return console.log("this is z");} function foobar(){ this.bar = console.log(foo,z); }(foo = w || x || y, z); foobar();
changing the value of z in (foo = w || x || y, z) .
var w = 0, x = 1,y = 2; var z = function(){return console.log("this is z");} function foobar(){ this.bar = console.log(foo,z); }(foo = w || x || y, z=4); foobar();
I assume that placing variables inside ( ) after } function is the same as declaring a new variable.
Another test.
var w = 0, x = 1,y = 2,z = 1; function foobar(){ var bar = 10,z=2; console.log(z); }(foo = w || x || y, z=4); console.log(foo,z);
However, in such a scenario. JSFiddle Link
//Self-Executing Anonymous Function: Part 2 (Public & Private) (function( skillet, $, undefined ) { //Private Property var isHot = true; //Public Property skillet.ingredient = "Bacon Strips"; //Public Method skillet.fry = function() { var oliveOil; addItem( "\t\n Butter \n\t" ); addItem( oliveOil ); console.log( "Frying " + skillet.ingredient ); }; //Private Method function addItem( item ) { if ( item !== undefined ) { console.log( "Adding " + $.trim(item) ); } } }( window.skillet = window.skillet || {}, jQuery )); //Public Properties console.log( skillet.ingredient ); //Bacon Strips //Public Methods skillet.fry(); //Adding Butter & Fraying Bacon Strips //Adding a Public Property skillet.quantity = "12"; console.log( skillet.quantity ); //12 //Adding New Functionality to the Skillet (function( skillet, $, undefined ) { //Private Property var amountOfGrease = "1 Cup"; //Public Method skillet.toString = function() { console.log( skillet.quantity + " " + skillet.ingredient + " & " + amountOfGrease + " of Grease" ); console.log( isHot ? "Hot" : "Cold" ); }; }( window.skillet = window.skillet || {}, jQuery )); try { //12 Bacon Strips & 1 Cup of Grease skillet.toString(); //Throws Exception } catch( e ) { console.log( e.message ); //isHot is not defined }
It seems that if you delete , jQuery , it will only write Bacon Strips logs. See this link. Link to another JSFiddle ( , jQuery deleted)
I really do not understand. But why , jQuery inside the ( ) after } function is considered a link to fully run the code when the jQuery library is already on
Removing $.trim from the code seems to work fine again. But I still donโt understand how this link works. JSFiddle reference without jQuery and $ .trim