Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- ...
- code
- ...
- })();
- function outerFunction() {
- function innerFunction() {
- // code
- }
- }
- var globalVariable;
- function someFunction() {
- var localVariable;
- }
- function globalFunction() {
- var localFunction1 = function() {
- //I'm anonymous! But localFunction1 is a reference to me!
- };
- function localFunction2() {
- //I'm named!
- }
- }
- (function() {
- var private_var;
- function private_function() {
- //code
- }
- })()
- var myPlugin = (function() {
- var private_var;
- function private_function() {
- }
- return {
- public_function1: function() {
- },
- public_function2: function() {
- }
- }
- })()
- (function(jQ) { ... code ... })(jQuery)
- var someFunction = function(){ console.log('wagwan!'); };
- (function() { /* function scope starts here */
- console.log('start of IIFE');
- var myNumber = 4; /* number variable declaration */
- var myFunction = function(){ /* function variable declaration */
- console.log('formidable!');
- };
- var myObject = { /* object variable declaration */
- anotherNumber : 1001,
- anotherFunc : function(){ console.log('formidable!'); }
- };
- console.log('end of IIFE');
- })(); /* function scope ends */
- someFunction(); // reachable, hence works: see in the console
- myFunction(); // unreachable, will throw an error, see in the console
- myObject.anotherFunc(); // unreachable, will throw an error, see in the console
- var someFunction = function(){ console.log('wagwan!'); };
- var myMainFunction = function() {
- console.log('start of IIFE');
- var myNumber = 4;
- var myFunction = function(){ console.log('formidable!'); };
- var myObject = {
- anotherNumber : 1001,
- anotherFunc : function(){ console.log('formidable!'); }
- };
- console.log('end of IIFE');
- };
- myMainFunction(); // I CALL "myMainFunction" FUNCTION HERE
- someFunction(); // reachable, hence works: see in the console
- myFunction(); // unreachable, will throw an error, see in the console
- myObject.anotherFunc(); // unreachable, will throw an error, see in the console
- var italianSayinSomething = function(){ console.log('mamamia!'); }();
- var someFunction = function(){ console.log('wagwan!'); };
- var myMainFunction = function() {
- console.log('start of IIFE');
- var myNumber = 4;
- var myFunction = function(){ console.log('formidable!'); };
- var myObject = {
- anotherNumber : 1001,
- anotherFunc : function(){ console.log('formidable!'); }
- };
- console.log('end of IIFE');
- }();
- someFunction(); // reachable, hence works: see in the console
- myFunction(); // unreachable, will throw an error, see in the console
- myObject.anotherFunc(); // unreachable, will throw an error, see in the console
- function(){ console.log('mamamia!'); }();
- (function(){ console.log('mamamia!'); })(); // live demo: jsbin.com/zokuwodoco/1/edit?js,console.
- +function(){ console.log('mamamia!'); }(); // live demo: jsbin.com/wuwipiyazi/1/edit?js,console
- -function(){ console.log('mamamia!'); }(); // live demo: jsbin.com/wejupaheva/1/edit?js,console
- var someFunction = function(){ console.log('wagwan!'); };
- (function() {
- console.log('start of IIFE');
- var myNumber = 4;
- var myFunction = function(){ console.log('formidable!'); };
- var myObject = {
- anotherNumber : 1001,
- anotherFunc : function(){ console.log('formidable!'); }
- };
- console.log('end of IIFE');
- })();
- someFunction(); // reachable, hence works: see in the console
- myFunction(); // unreachable, will throw an error, see in the console
- myObject.anotherFunc(); // unreachable, will throw an error, see in the console
- (function() {
- var myNumber = 4; /* number variable declaration */
- var myFunction = function(){ /* function variable declaration */
- console.log('formidable!');
- };
- var myObject = { /* object variable declaration */
- anotherNumber : 1001,
- anotherFunc : function(){ console.log('formidable!'); }
- };
- myOtherFunction = function(){ /* oops, an assignment instead of a declaration */
- console.log('haha. got ya!');
- };
- })();
- myOtherFunction(); // reachable, hence works: see in the console
- window.myOtherFunction(); // works in the browser, myOtherFunction is then in the global scope
- myFunction(); // unreachable, will throw an error, see in the console
- (function() {
- var x = 2;
- // do stuff with x
- })();
- (function($) { ...code...})(jQuery);
- navigator.html5={
- canvas: (function(){
- var dc= document.createElement('canvas');
- if(!dc.getContext) return 0;
- var c= dc.getContext('2d');
- return typeof c.fillText== 'function'? 2: 1;
- })(),
- localStorage: (function(){
- return !!window.localStorage;
- })(),
- webworkers: (function(){
- return !!window.Worker;
- })(),
- offline: (function(){
- return !!window.applicationCache;
- })()
- }
- (function() {
- 'use strict';
- //Your code from here
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement