What does this “(function(){});”, a function inside brackets, mean in javascript? [duplicate]

You’re immediately calling an anonymus function with a specific parameter. An example: (function(name){ alert(name); })(‘peter’) This alerts “peter“. In the case of jQuery you might pass jQuery as a parameter and use $ in your function. So you can still use jQuery in noConflict-mode but use the handy $: jQuery.noConflict() (function($){ var obj = $(‘<div/>’, … Read more

How do I declare a namespace in JavaScript?

I use the approach found on the Enterprise jQuery site: Here is their example showing how to declare private & public properties and functions. Everything is done as a self-executing anonymous function. (function( skillet, $, undefined ) { //Private Property var isHot = true; //Public Property skillet.ingredient = “Bacon Strips”; //Public Method skillet.fry = function() … Read more