Outils du site

Le Rire est le propre de l'Homme (?) [Rabelais]

56-tools:javascript

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
56-tools:javascript [2017/10/18 15:31] – [Closure] Roge56-tools:javascript [2018/01/20 02:59] (Version actuelle) – [références] Roge
Ligne 11: Ligne 11:
 [[http://www.crockford.com/javascript/private.html|Doub Crockford]] //"an inner function always has access to the vars and parameters of its outer function, **even after the outer function has returned**"// [[http://www.crockford.com/javascript/private.html|Doub Crockford]] //"an inner function always has access to the vars and parameters of its outer function, **even after the outer function has returned**"//
  
 +http://2ality.com/2011/04/modules-and-namespaces-in-javascript.html
 ===== ES6 ===== ===== ES6 =====
  
Ligne 122: Ligne 123:
 </code> </code>
  
-Subtil behavour:+
 <code> <code>
 // closure example // closure example
 +function makeAdder(x) {
 +  return function(y) {
 +    return x + y;
 +  };
 +}
  
-function myContext() { +var add5 makeAdder(5); 
-    var x = 0; +var add100 makeAdder(100);
-    function f() { +
-        x += 1; +
-        return x; +
-    }; +
-    return f; +
-}; +
- +
-// g is now function with closure +
-var g1 myContext(); +
-var g2 myContext();+
  
-// g maintains a state +console.log(add5(2));  // 7 
-console.log("g1: "+g1());         // "g1: 1" +console.log(add100(2)); // 102
-console.log("g2: "+g2());         // "g2: 1" +
-console.log("g1: "+g1());         // "g1: 2"+
 </code> </code>
  
Ligne 392: Ligne 386:
 [[http://jsfiddle.net/jk3vstnb/|Fade in out message]] [[http://jsfiddle.net/jk3vstnb/|Fade in out message]]
  
 +[[http://jsfiddle.net/na7bkoo8/|JS Sorting an HTML table]]
 ===== Tests scripts web: jsbin ===== ===== Tests scripts web: jsbin =====
  
Dernière modification : 2017/10/18 15:31