Javascriptmall med namnrymd - CSS-tricks

Anonim

Själv anropande anonym funktion tilldelad den yournamespacechoiceglobala variabeln. Serverar effekten av att hålla alla funktioner och variabler privata för denna funktion. För att exponera en funktion eller variabel måste vi uttryckligen returnera den längst ner i funktionen. Remapsar jQuery till $.

var yournamespacechoice = (function ($) ( var publicfunction; function privatefunction() ( // function only available within parent function ) publicfunction = function publicfunction() ( // public function available outside of this funtion ); // Expose any functions that we need to access outside of this scope. Use yournamespacechoice.functionName() to call them. return ( publicfunction: publicfunction ); )(window.$));