Académique Documents
Professionnel Documents
Culture Documents
Exécution :
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
1*
test.html:4:8
Arguments { … }
test.html:5:8
undefined
test.html:6:8
undefined
test.html:7:8
undefined
test.html:8:8
undefined
test.html:9:8
2*
test.html:4:8
Arguments { 0: […], … }
test.html:5:8
Array [ "Un" ]
test.html:6:8
undefined
test.html:7:8
undefined
test.html:8:8
undefined
test.html:9:8
3*
test.html:4:8
Arguments { 0: […], 1: {…}, … }
test.html:5:8
Array [ "Un" ]
test.html:6:8
Object { d: 2 }
test.html:7:8
undefined
test.html:8:8
undefined
test.html:9:8
4*
test.html:4:8
Arguments { 0: […], 1: {…}, 2: "Trois", … }
test.html:5:8
Array [ "Un" ]
test.html:6:8
Object { d: 2 }
test.html:7:8
Trois
test.html:8:8
undefined
test.html:9:8
5*
Variables & Functions - 2 / 26 - mercredi, 28. novembre 2018 (6:52 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
test.html:4:8
Arguments { 0: […], 1: {…}, 2: "Trois", 3: true, … }
test.html:5:8
Array [ "Un" ]
test.html:6:8
Object { d: 2 }
test.html:7:8
Trois
test.html:8:8
true
test.html:9:8
6*
test.html:4:8
Arguments { 0: […], 1: {…}, 2: "Trois", 3: true, 4: 5, … }
test.html:5:8
Array [ "Un" ]
test.html:6:8
Object { d: 2 }
test.html:7:8
Trois
test.html:8:8
true
test.html:9:8
1* test.html:4:8
undefined test.html:5:8
undefined test.html:6:8
undefined test.html:7:8
undefined test.html:8:8
undefined test.html:9:8
undefined test.html:10:8
2* test.html:4:8
Array [ "Un" ] test.html:5:8
Array [ "Un" ] test.html:6:8
undefined test.html:7:8
undefined test.html:8:8
undefined test.html:9:8
undefined test.html:10:8
3* test.html:4:8
Array [ "Un" ] test.html:5:8
Array [ "Un" ] test.html:6:8
Object { d: 2 } test.html:7:8
Object { d: 2 } test.html:8:8
undefined test.html:9:8
undefined test.html:10:8
4* test.html:4:8
Array [ "Un" ] test.html:5:8
Array [ "Un" ] test.html:6:8
Object { d: 2 } test.html:7:8
Object { d: 2 } test.html:8:8
Trois test.html:9:8
undefined test.html:10:8
5* test.html:4:8
Array [ "Un" ] test.html:5:8
Array [ "Un" ] test.html:6:8
Object { d: 2 } test.html:7:8
Object { d: 2 } test.html:8:8
Trois test.html:9:8
true test.html:10:8
6* test.html:4:8
Array [ "Un" ] test.html:5:8
Array [ "Un" ] test.html:6:8
Object { d: 2 } test.html:7:8
Object { d: 2 } test.html:8:8
Trois test.html:9:8
true test.html:10:8
Un autre exemple :
var fct=f();
for(var k=2;k<5;k++){
const r=fct(k * Math.round((Math.random()*10)));
console.log("y==(k*Math)=="+r[0]+" | x=="+r[1]+
" | x+=y=="+(1*r[1]+r[0])+" | "+
"x("+r[1]+")*k("+k+")="+r[2](k));
}
</script>
// y==(k*Math)==18 | x==18 | x+=y==36 | x(18)*k(2)=36
// y==(k*Math)==9 | x==27 | x+=y==36 | x(27)*k(3)=81
// y==(k*Math)==24 | x==51 | x+=y==75 | x(51)*k(4)=204
ou encore :
Exécution :
9 test.html:7:3
10 test.html:10:3
<script type="text/javascript">
"use strict";
function fbase(x){
return function fpow(y){
return "Math.pow("+x+","+y+")="+
Math.pow(x,y) ;
}
}
var fpow2=fbase(2);
console.log("1 TB="+fpow2(40)+" Bytes")
console.log("=Math.pow(1024,4)="
+Math.pow(1024,4)+" Bytes")
</script>
Exécution :
Exécution :
<script type="text/javascript">
"use strict";
// fpow est une fonctio ordinaire
// qu'on utilisera dans le currying.
function fpow (x, y) {
return "Math.pow("+x+","+y+") = "+
Math.pow(x,y)
}
//////////////////////////////
// EXECUTION EFFECTIVE DE LA FONCTION
//////////////////////////////
//A///////////////////////////
///// Appel DIRECT fpow via l'instruction
// powx=curry( *** F_POW *** sans args)
// Excusez le underscore et les majuscules.
//B//////////////////////////
///// Appel INDIRECT de fpow via alias curry
// powx = curry(*** POW_X *** , 2éarg)
// sans _f_ Excusez les majuscules.
// x garde tjs sa valeur x=5 ds pow5
// Appel de fpow avec un autre 2é arg via pow5
let pow1 = curry(pow5,6)
// 2e appel de fpow sans arg
// ... SANS UN PARAMETRE.
console.log(pow1())
// x garde tjs sa valeur x=10 ds pow10
// Appel de fpow avec un autre 2é arg via pow10
let pow2 = curry(pow10,6)
// 2e appel de fpow sans arg
console.log(pow2())
// x garde tjs sa valeur x=5 ds pow5
// Appel de fpow avec un autre 2é arg via pow5
let pow3 = curry(pow5,3)
// 2e appel de fpow sans arg
console.log(pow3())
// x garde tjs sa valeur x=10 ds pow10
// Appel de fpow avec un autre 2é arg via pow5
let pow4 = curry(pow10,3)
// 2e appel de fpow sans arg
console.log(pow4())
//A///////////////////////////
///// Encore Appel DIRECT fpow via curry
// x garde tjs sa valeur x=5 ds pow5
// Appel fpow avec dernier arg y=5 => exec fct
console.log(pow5(10))
</script>
Variables & Functions - 11 / 26 - mercredi, 28. novembre 2018 (6:52 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
Exécution :
Math.pow(5,1) = 5 test.html:36:2
Math.pow(10,1) = 10 test.html:39:2
Math.pow(5,6) = 15625 test.html:52:2
Math.pow(10,6) = 1000000 test.html:58:2
Math.pow(5,3) = 125 test.html:64:2
Math.pow(10,3) = 1000 test.html:70:2
Math.pow(5,10) = 9765625 test.html:77:2
<script type="text/javascript">
"use strict";
<script type="text/javascript">
"use strict";
var x = (a) => (b) => (c) => (d) => a + b + c + d;
console.log( x(1)(2)(3)(4) );
</script>
Exécution :
10
Variables & Functions - 14 / 26 - mercredi, 28. novembre 2018 (6:52 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
Exécution :
10
a=function(a){
return b=function(b){
return c=function(c){
return function(d){
Variables & Functions - 15 / 26 - mercredi, 28. novembre 2018 (6:52 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
return a+b+c+d
}
}
}
}
Exécution :
10
<script type="text/javascript">
"use strict";
var fa, fb, fc, fd; // Noms des fonctions
fa=function(){
const a=aL;
return fb=function(){
let b=bL;
return fc=function(){
var c=cL;
return fd=function(){
let d=dL;
return a+b+c+d
}
}
Variables & Functions - 16 / 26 - mercredi, 28. novembre 2018 (6:52 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
}
}
const aL=1, bL=2, cL=3, dL=4;
let res = (fa)(fb)(fc)(fd)();
console.log(res);
</script>
Exécution :
10
<script type="text/javascript">
'use strict';
// Definir la fonction callback.
function primes(val /*, idx, ar */) {
let high = Math.round(Math.sqrt(val))
for (var div = 2; div <= high; div++) {
if (val % div == 0) return false;
}
return true;
}
Exécution :
Array [ 101, 103, 107, 109, 113, 127, 131, 137, 139, 149 ]
Variables & Functions - 17 / 26 - mercredi, 28. novembre 2018 (6:52 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
<script type="text/javascript">
'use strict';
Exécution :
Avec Object.getOwnPropertyNames(window) :
<script type="text/javascript">
'use strict';
var noms_css =
Object.getOwnPropertyNames(window).filter(fcss);
for (var i in noms_css)
console.log(noms_css[i]);
// Extraire les noms commençant par "css".
function fcss(val) {
if ((val.substr(0, 3)).toLowerCase() == "css")
return true;
else
Exécution :
CSSStyleRule
CSSFontFaceRule
CSSPrimitiveValue
CSSStyleDeclaration
CSSStyleSheet
CSSPageRule
CSSSupportsRule
CSSMozDocumentRule
CSSKeyframeRule
CSSGroupingRule
CSS2Properties
CSSFontFeatureValuesRule
CSSRuleList
CSSMediaRule
CSSCounterStyleRule
CSSImportRule
CSSValue
CSSNamespaceRule
CSSRule
CSS
CSSKeyframesRule
CSSConditionRule
CSSValueList
Avec Array.map() :
<script>
var myArray = [1, 2, 3];
var newArray = myArray.map(function(x) { return x+".
" + x*x; });
console.log(newArray);
</script>
Exécution :
Array.map() :
<script>
"use strict";
var txt = [
"Kelakonov",
["Kretchnonskof","Qelaïnokonovitchsk"],
{nom:"Andreanopovickz",pnom:"Bretilonov"},
"Kenailovocz", "Qelaïnkenikov"
];
Exécution :
Variables & Functions - 20 / 26 - mercredi, 28. novembre 2018 (6:52 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
Avec Array.filter() :
Variables & Functions - 21 / 26 - mercredi, 28. novembre 2018 (6:52 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
<script>
"use strict";
var dslimites = function(val) {
if (typeof val !== 'number')
return false;
else
return val >= this.minimum && val <=
this.maximum;
}
var numbers = [25, 17, "15", 6, "texte", -1, 12];
var oLimites = { minimum: 10, maximum: 20 }
var result = numbers.filter(dslimites, oLimites);
console.log(result);
</script>
Exécution :
Array [ 17, 12 ]
0: 17
1: 12
length: 2
__proto__: Array []
<script type="text/javascript">
function ftag(e) {
var targ
if (!e) var e = window.event
if (e.target) targ = e.target
else if (e.srcElement) targ = e.srcElement
if (targ.nodeType == 3) // Contourner bug ds Safari
Exécution :
Exécution :
texte initial
T E X T E I N I T I A L
<script type="text/javascript">
function f(){
document.write("Alléluia")
v=document.getElementById("idiv").innerHTML;
v=v.toUpperCase();
console.log(v);
}
</script>
<body onload=f() id="ibody">
<div id="idiv"">texte initial</div>
</body>
Exécution :
<script type="text/javascript">
"use strict";
function f(){
// document.write("Alléluia");
document.getElementById("ibody").innerHTML+=
"Alleluia";
var v;
v = document.getElementById("idiv").innerHTML
console.log(v);
v = v.toUpperCase();
console.log(v);
}
</script>
<body onload=f() id="ibody">
<div id="idiv"">
texte initial
</div>
</body>
Exécution :
Dans le document :
texte initial
Alleluia
Dans la console :