Explorer les Livres électroniques
Catégories
Explorer les Livres audio
Catégories
Explorer les Magazines
Catégories
Explorer les Documents
Catégories
On a vu que les fonctions sont des objets tout faits. Elles ont en effet des
méthodes (par exemple les méthodes Apply , Call , Bind ) :
I. La méthode « Bind() » :
<button>Tirez un Candidat</button>
<textarea id="txtar" readonly></textarea>
<script type="text/javascript">
"use strict";
var candidat = {
profil :[
{ID:"Martinez G.", matric:11},
{ID:"Robinson T", matric:55},
///// {ID:"Melissa R", matric:00},
// SyntaxError: "0"-prefixed octal literals and
octal escape sequences are deprecated; for octal lit-
erals use the "0o" prefix instead [FIREFOX]
// Uncaught SyntaxError: Octal literals are not
allowed in strict mode. [YANDEX]
Variables & Functions 1 / 19 mardi, 22. janvier 2019 (8:14 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-
II
docu-
ment.getElementsByTagName("button")[0].addEventListen
er(
'click', candidat.clickHandler.bind(candidat),
false);
</script>
Exécution :
Tirez un Candidat
Robinson T #55 ***Sur les 5 Prétendants.
<script type="text/javascript">
"use strict";
var user = {
// Candidats, variables locales à objet user
place:" LOCAL =user",
data :[ // Propriété
{ID:"Belinda U", Matric:55},
{ID:"Nelson U", Matric:66},
{ID:"Lesmor U", Matric:77},
{ID:"Belafonté U", Matric:77},
{ID:"Zirgont U", Matric:88},
{ID:"Zamith U", Matric:99}
],
this.data.map(function(dummy){console.log(++cptr+">
"+dummy.ID+" "+dummy.Matric)});
}
}
Exécution :
******RETENU* = Petgorje G 44
Parmi 3 prétendants ( GLOBAL =window) :
1> Gregoire G 22
2> Bolivia G 33
3> Petgorje G 44
******RETENU* = Zirgont U 88
Parmi 6 prétendants ( LOCAL =user) :
1> Belinda U 55
2> Nelson U 66
3> Lesmor U 77
4> Belafonté U 77
5> Zirgont U 88
6> Zamith U 99
En mode standard (non «use strict»;) JS est très tolérant et laisse passer
l’instruction « var dispVar = user.disp; » qui était rejetée en
mode «use strict;». this est du scope global car c’est là que le pointeur à
la méthode disp() est défini.
<script type="text/javascript">
Variables & Functions 4 / 19 mardi, 22. janvier 2019 (8:14 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-
II
// "use strict";
var user = {
// Candidats, variables locales à objet user
place:" LOCAL =user",
data :[ // Propriété
{ID:"Belinda U", Matric:55},
{ID:"Nelson U", Matric:66},
{ID:"Lesmor U", Matric:77},
{ID:"Belafonté U", Matric:77},
{ID:"Zirgont U", Matric:88},
{ID:"Zamith U", Matric:99}
],
this.data.map(function(dummy){console.log(++cptr+">
"+dummy.ID+" "+dummy.Matric)});
}
}
Exécution :
******RETENU* = Gregoire G 22
Parmi 3 prétendants ( GLOBAL =window) :
1> Gregoire G 22
2> Bolivia G 33
3> Petgorje G 44
******RETENU* = Bolivia G 33
Parmi 3 prétendants ( GLOBAL =window) :
1> Gregoire G 22
2> Bolivia G 33
3> Petgorje G 44
******RETENU* = Nelson U 66
Parmi 6 prétendants ( LOCAL =user) :
1> Belinda U 55
2> Nelson U 66
3> Lesmor U 77
4> Belafonté U 77
5> Zirgont U 88
6> Zamith U 99
<script type="text/javascript">
"use strict";
var user = {
// Candidats, variables locales à objet user
place:" LOCAL =user",
data :[ // Propriété
{ID:"Belinda U", Matric:55},
{ID:"Nelson U", Matric:66},
{ID:"Lesmor U", Matric:77},
{ID:"Belafonté U", Matric:77},
{ID:"Zirgont U", Matric:88},
Variables & Functions 7 / 19 mardi, 22. janvier 2019 (8:14 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-
II
{ID:"Zamith U", Matric:99}
],
this.data.map(function(dummy){console.log(++cptr+">
"+dummy.ID+" "+dummy.Matric)});
}
}
Exécution :
******RETENU* = Zirgont U 88
Parmi 6 prétendants ( LOCAL =user) :
1> Belinda U 55
2> Nelson U 66
3> Lesmor U 77
4> Belafonté U 77
Variables & Functions 8 / 19 mardi, 22. janvier 2019 (8:14 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-
II
5> Zirgont U 88
6> Zamith U 99
******RETENU* = Gregoire G 22
Parmi 3 prétendants ( LOCAL =producer) :
1> Gregoire G 22
2> Bolivia G 33
3> Petgorje G 44
<script type="text/javascript">
"use strict";
/*6*/ !function(){
console.log("!function()")} // 2è appel
(console.log("!function()_1")) // 1è appel
(console.log("!function()_2")) // 3è appel
(console.log("!function()_3")); // Erreur
</script>
Dans la console :
fct()
length: 0
name: "fct"
prototype: Object { … }
__proto__: function ()
fct2()
length: 0
name: "fct2"
prototype: Object { … }
__proto__: function ()
fct3()
name: "fct3"
__proto__: function ()
fct4
anonymous()
arguments: null
caller: null
length: 0
name: "anonymous"
prototype: Object { … }
__proto__: function ()
<script type="text/javascript">
function la_fct(p){
// Sans autre paramètre que le nom de la fonction,
// donne son Type (expensible), affiché comme poin-
teur
console.log(la_fct);
function appeleur(){
la_fct("***ARGUMENT***",2)
}
appeleur();
</script>
Avec document.write :
function la_fct(p){
document.write(la_fct); // Type, dépliable
document.write(p+" + "+la_fct); // Contenu =
Code. }
Variables & Functions 11 / 19 mardi, 22. janvier 2019 (8:14 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-
II
Avec console.log :
function la_fct()
Exemple simple :
<script type="text/javascript">
var Pomme = {
couleur: "rouge",
poids: 50,
};
console.log(Pomme);
console.log("Notre pomme : " + Pomme);
</script>
Exécution :
Avec le nom d’un objet seul comme paramètre, console.log affiche selon
Variables & Functions 12 / 19 mardi, 22. janvier 2019 (8:14 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-
II
les navigateurs, soit seulement le nom de l’objet comme pointeur qu’on
peut cliquer pour voir les détails de la structure de l’objet., soit directe-
ment ces détails.
Concernant le typecasting :
Et dans un code :
31 + 23 = test.html:6:4
3123 (test.html:7:4) 54 (test.html:8:4)
54 (test.html:9:4) 54 (test.html:11:4)
54 (test.html:13:4)
Note :
<script type="text/javascript">
Pomme = {
couleur: "rouge",
poids: 50,
toString:function(){
v= "Couleur = "+this.couleur+" ,
poids = "+this.poids;
return v;
}
}
Exécution :
{…}
couleur: "rouge"
poids: 50
__proto__: Object { … }
<script type="text/javascript">
function notre_fct(p1,p2){
couleur= p1;
var poids= p2;
toString=function(){
v= "Coul = "+couleur+" , pds = "+poids
return v;
}
}
Exécution :
function notre_fct()
notre_fct()
arguments: null
caller: null
Variables & Functions 16 / 19 mardi, 22. janvier 2019 (8:14 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-
II
name: "notre_fct"
__proto__: ()
apply: function apply()
arguments: null
bind: function bind()
call: function call()
caller: null
constructor: function Function()
isGenerator: function isGenerator()
length: 0
name: ""
toSource: function toSource()
toString: function toString()
Symbol(Symbol.hasInstance): undefined
__proto__: Object { … }
Mots-clés :
fonctions,curry,currying,redéfinition,fonction fermeture,closure,paramètre du
reste,blocs de code,réutilisables,fonctions nommées,fonctions ano-
nymes,expressions de fonctions immédiatement invo-
quées,eventHandler,affecter,variable,pointeur,script,types de fonction,syntaxes de
fonction.
diasfb@mail2world.com
Autre Lecture :
https://www.scribd.com/document/374738470/Le-Plus-Grand-Secret-de-La-
Creation
• https://www.scribd.com/document/377036251/Le-Dosage-Des-
Medicaments-en-Cac-Cas
• https://www.scribd.com/document/377035454/Le-Hasard-Des-
Thermometres-Non-contact-a-Infrarouge
• https://www.scribd.com/document/376222482/Petite-Introduction-
Aux-Fonctions-JavaScript
• https://www.scribd.com/document/376221919/La-Foi-en-Jesus-Christ-
Pour-Quoi-Faire
• https://www.scribd.com/document/375689778/Lacuite-visuelle-
Variables & Functions 18 / 19 mardi, 22. janvier 2019 (8:14 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-
II
angulaire
• https://www.scribd.com/document/375349851/La-variable-This
• https://www.scribd.com/document/375024162/Fonctions-Imbriquees-
en-JS
• https://www.scribd.com/document/374789297/Format-Interne-Des-
Objets-JavaScript
• https://www.scribd.com/document/374788758/Iterations-en-JavaScript
• https://www.scribd.com/document/374738470/Le-Plus-Grand-Secret-
de-La-Creation
• https://www.scribd.com/document/374597969/Nouvelle-Formule-d-
IMC-indice-de-doduite-Selon-Dr-Diasoluka
• https://www.scribd.com/document/373847209/Property-Descriptors
• https://www.scribd.com/document/373833282/l-Objet-Global-Window
• https://www.scribd.com/document/372665249/Javascript-Tome-II
• https://www.scribd.com/document/355291488/motilite-oculaire-2
• https://www.scribd.com/document/355291239/motilite-oculaire-I
• https://www.scribd.com/document/355290248/Script-d-Analyses-Des-
Reflexes-Pupillomoteurs
• https://www.scribd.com/document/321168468/Renseignements-Id-et-
Anthropometriques
• https://www.scribd.com/document/320856721/Emission-31-Jul-2016
• https://www.scribd.com/document/318182982/Complication-Visuelle-
du-Traitement-de-La-Malaria
• https://www.scribd.com/document/318180637/Rapport-Entre-
Oxymetrie-Et-Type-Respiration
• https://www.scribd.com/document/315746265/Classification-Des-
Medicaments
• https://www.scribd.com/document/315745909/Incongruences-
Heresies-et-Heterodoxies-de-la-Notion-de-Laboratoire
• https://www.scribd.com/document/315745725/Rapport-Entre-
Oxymetrie-Et-Type-Respiration