Académique Documents
Professionnel Documents
Culture Documents
<script type="text/javascript">
"use strict";
var dObj = {
couleur:"rose",
50: "Cinquante",
age:45,
[2]:function(){console.log("Hello")},
3: "Trois",
["quatre"]:function(){console.log("quatre")}
}
// var dObj = new dObj();
console.log(dObj["couleur"])
console.log(dObj["50"])
console.log(dObj.age)
dObj[2]()
console.log(dObj[3])
dObj["quatre"]()
console.log("=====")
for(var i in dObj)console.log(i+". "+dObj[i])
console.log(Object.values(dObj))
console.log(">===<")
for(i in dObj)console.log(dObj[i])
</script>
Exécution :
rose test.html:14:3
Cinquante test.html:15:3
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
45 test.html:16:3
Hello test.html:7:23
Trois test.html:18:3
quatre test.html:9:30
===== test.html:20:3
2. function(){console.log("Hello")} test.html:21:21
3. Trois test.html:21:21
50. Cinquante test.html:21:21
couleur. rose test.html:21:21
age. 45 test.html:21:21
quatre. function(){console.log("quatre")} test.html:21:21
Array [
dObj(), "Trois", "Cinquante", "rose", 45, dObj()
] test.html:22:3
>===< test.html:23:3
dObj()
length: 0
name: "2"
prototype: Object { … }
__proto__: function () test.html:24:17
Trois test.html:24:17
Cinquante test.html:24:17
rose test.html:24:17
45 test.html:24:17
dObj() test.html:24:17
length: 0
name: "quatre"
prototype: Object { … }
__proto__: function ()
let _obj =
{"5":'ally', b:'belly', 3:'chore', _obj:45};
console.log(_obj._obj); // 45
Les propriétés sont des objets dont les propriétés sont leurs attributs.
Comme dit ci-dessus, [[value]] est la valeur que vous attribuez ou at-
tendez de l’objet.
console.log(Object.getOwnPropertyDescriptors(obj));
// Object { nom: {…}, matr: {…} }
// {…}
// matr: Object { value: 45, writable: true, enumerable:
true, … }
// nom: Object { value: "nomEl", writable: true, enumer-
able: true, … }
// {…}
// matr: {…}
Variables & Functions - 4 / 14 - vendredi, 6. juillet 2018 (10:11 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
// configurable: true
// enumerable: true
// value: 45
// writable: true
// nom: {…}
// configurable: true
// enumerable: true
// value: "nomEl"
// writable: true
console.log(obj["nom"], obj.matr);
// nomEl 45
console.log(Object.getOwnPropertyDescriptor(obj,"nom"));
// Object { value: "nomEl", writable: true, enumerable:
true, configurable: true }
// {…}
// configurable: true
// enumerable: true
// value: "nomEl"
// writable: true
console.log(Object.getOwnPropertyDescriptor(
obj,"defProp"));
// Object { value: "definedProp", writable: false, enumer-
able: false, configurable: false }
// {…}
// configurable: false
// enumerable: false
// value: "definedProp"
// writable: false
</script>
Object.getOwnPropertyDescriptors([objet])
On peut définir les propriétés d’un objet [et éventuellement les attri-
buts de ces propriétés] de plusieurs façons ;
console.dir("obj.dirProp=",obj.dirProp);
// obj.dirProp= Direct Property
////////////////////////////
///// Dê BUT GETTER et SETTER
////////////////////////////
// Accê s ordinaire
console.dir("obj=",obj);
// obj=
// Object { nom: "nomEl", matr: 45, dirProp: "Direct
Property", … }
// {…}
// defProp: "definedProp"
// defPropA: "Affectation ordinaire, toujours pos-
sible!"
// defPropX: "definedProp Extended"
// dirProp: "Direct Property"
// matr: "2018"
// nom: "JavaScript"
// prod: Getter & Setter
// <get>: function get()
// <set>: function set()
// Accê s par GETTER
console.dir("OBJ.PROD = : ",obj.prod);
// OBJ.PROD = : obj.nom= nomEl , obj.matr=45
/*
defProp: {…}
configurable: false
enumerable: false
value: "definedProp"
writable: false
defPropA: {…}
configurable: true
enumerable: true
value: "Affectation ordinaire, toujours possible!"
writable: true
defPropX: {…}
Variables & Functions - 8 / 14 - vendredi, 6. juillet 2018 (10:11 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
configurable: true
enumerable: false
value: "definedProp Extended"
writable: false
dirProp: {…}
configurable: true
enumerable: true
value: "Direct Property"
writable: true
matr: {…}
configurable: true
enumerable: true
value: 2018
writable: true
nom: {…}
configurable: true
enumerable: true
value: "JavaScript"
writable: true
prod: {…}
configurable: false
enumerable: false
get: function get()
set: function set()
*/
</script>
var obj = {
libelle: 'Nom Produit',
prix: 2018,
get detailsProd() {
return {nomProd:this.libelle, prixProd:this.prix};
},
set detailsProd(name) {
var parts = name.split(" ");
this.libelle = parts[0];
Variables & Functions - 9 / 14 - vendredi, 6. juillet 2018 (10:11 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
this.prix = parts[1];
}
};
console.log("obj=",obj);
// obj=
// Object { libelle: "Nom Produit", prix: 2018, details-
Prod: Getter & Setter }
// {…}
// detailsProd: Getter & Setter
// libelle: "ECMASCRIPT_2018"
// prix: "3USD"
console.log("obj.libelle=",obj.libelle);
// obj.libelle= Nom Produit
console.log("obj.prix=",obj.prix);
// obj.prix= 2018
// AVEC YANDEX
//test.html:21 obj= {libelle: "Nom Produit", prix: 2018}
// detailsProd: (...)
// libelle: "ECMASCRIPT_2018"
// prix: "3USD"
// get detailsProd: ƒ detailsProd ()
// set detailsProd: ƒ detailsProd (name)
// __proto__: Object
//test.html:29 obj.libelle= Nom Produit
//test.html:32 obj.prix= 2018
/* obj.detailsProd =
1er {nomProd: "ECMASCRIPT_2018", prixProd: "3USD"}
A nomProd:"ECMASCRIPT_2018"
B prixProd:"3USD"
C __proto__:Object
1er detailsProd:(...)
2e libelle:"ECMASCRIPT_2018"
3e prix:"3USD"
4e get detailsProd:ƒ detailsProd()
5th set detailsProd:ƒ detailsProd(name)
et
N.B. : Les propriété ne peuvent avoir que soit des valeurs, soit des ac-
cesseurs (set et get) , jamais les deux à la fois.
get detailsProd() {
return {nomProd:this.libelle, prixProd:this.prix};
},
set detailsProd(name) {
var parts = name.split(",");
this.libelle = parts[0];
this.prix = parts[1];
}
};
// AFFECTER ou MODIFIER
console.log(obj.detailsProd = 'ECMASCRIPT 2018 ES 8, 10
USD AMê RICAINS');
// ECMASCRIPT 2018 ES 8, 10 USD AMê RICAINS
console.log("obj.libelle=",obj.libelle);
Variables & Functions - 12 / 14 - vendredi, 6. juillet 2018 (10:11 )
J.D.B. DIASOLUKA Nz. Luyalu JavaScript Tome-VI
// obj.libelle= ECMASCRIPT 2018 ES 8
console.log("obj.prix=",obj.prix);
// obj.prix= 10 USD AMê RICAINS
console.log("obj.detailsProd=",obj.detailsProd);
// obj.detailsProd=
// obj.detailsProd=
// Object { nomProd: "ECMASCRIPT 2018 ES 8", prixProd: "
10 USD AMê RICAINS" }
// {…}
// nomProd: "ECMASCRIPT 2018 ES 8"
// prixProd: " 10 USD AMê RICAINS"
</script>
diasfb@mail2world.com