Propriétés d’objets et leurs attributs - javascript tome xvi

LES PROPRIÉTÉS D’OBJETS ET LEURS ATTRIBUTS
JAVASCRIPT
(Programmation Internet)
VOL. VI
Po u r D é b u t e r
J.B. Dadet DIASOLUKA Luyalu Nzoyifuanga
+243 - 851278216 - 899508675 - 995624714 - 902263541 - 813572818
CHAPITRE 11 : LES PROPRIÉTÉS:
On peut accéder aux propriétés dun objet de plusieurs façons :
1 Par le nom de la propriété. entre guillemets dans des crochets
2 Par le nom de la propriété précédé dun point
3 Par un index
<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>
PROPRIÉTÉS & ATTRIBUTS DOBJETS
JavaScript Tome-VI
JDB DIASOLUKA Nz. Luyalu
-2/19- vendredi, 31. mai 2019 (7:32 )
Exécution :
rose test.html:14:3
Cinquante test.html:15:3
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 ()
Parcourir les éléments dune collection / itération (array, object...) avec
un itérateur comme keys ”!
Object.keys -> function keys()
Array.prototype.keys -> function keys()
PROPRIÉTÉS & ATTRIBUTS DOBJETS
JavaScript Tome-VI
JDB DIASOLUKA Nz. Luyalu
-3/19- vendredi, 31. mai 2019 (7:32 )
<script type="text/javascript"> "use strict";
let _arr = ['ally', 'belly', 'chore'];
let our_Aiterator = _arr.keys();
console.log(our_Aiterator); // Array Iterator { }
for (let i of our_Aiterator) {
console.log(i,_arr[i]); // 0 ally , 1 belly , 2 chore
}
let our_Aiterator2 = Object.keys(_arr);
console.log(our_Aiterator2); // Array [ "0", "1", "2" ]
for (let i of our_Aiterator2) {
console.log(i,_arr[i]); // 0 ally , 1 belly , 2 chore
}
let _obj =
{"5":'ally', b:'belly', 3:'chore', _obj:45};
// « let _obj » et « _obj:45 == _obj._obj=45 »
// ne partagent pas le même Name Space et
// n'interfèrent donc pas.
console.log(_obj);
// Object { 3: "chore", 5: "ally", b: "belly", _obj: 45 }
console.log(_obj._obj); // 45
let our_Oiterator = Object.keys(_obj);
console.log(our_Oiterator);
// Array [ "3", "5", "b", "_obj" ]
for (let i of our_Oiterator) {
console.log(i,_obj[i]);
// 3 chore , 5 ally , b belly , _obj 45
}
</script>
Ajouter des propriétés à un objet existant :
<script model="text/javascript"> "use strict";
let o = {
zumela:"Yende",
mbula:2019
}
PROPRIÉTÉS & ATTRIBUTS DOBJETS
JavaScript Tome-VI
JDB DIASOLUKA Nz. Luyalu
-4/19- vendredi, 31. mai 2019 (7:32 )
o.sika1 = "Mosusu";
o["sika2"]="Mombamba";
console.log(o);
</script>
CHAPITRE 12 : LES PROPRIÉTÉS ET LEURS ATTRIBUTS :
Les propriétés sont des objets dont les propriétés sont leurs attributs.
Sur https://www.ecma-international.org/ecma-262/8.0 nous lisons ceci :
6.1.7.1 Property Attributes
Attributes are used in this specification to define and explain the state of
Object properties. A data property associates a key value with the attrib-
utes listed in Table 2.
Table 2: Attrib-
utes of a Data
Property At-
tribute Name
Value Do-
main
Description
[[Value]]
Any
ECMAScript
language
type
The value retrieved by a get access of
the property.
PROPRIÉTÉS & ATTRIBUTS DOBJETS
JavaScript Tome-VI
JDB DIASOLUKA Nz. Luyalu
-5/19- vendredi, 31. mai 2019 (7:32 )
[[Writable]]
Boolean
Peut-être modifié [directement].
If false, attempts by ECMAScript code
to change the property's [[Value]] at-
tribute using [[Set]] will not succeed.
[[Enumerable]]
Boolean
Invisible dans certains contextes.
If true, the property will be enumerated
by a for-in enumeration (see 13.7.5).
Otherwise, the property is said to be
non-enumerable.
[[Configurable]]
Boolean
Peut être supprimée, ou
Son « property descriptor » changé.
If false, attempts to delete the property,
change the property to be an accessor
property, or change its attributes (other
than [[Value]], or changing [[Writable]]
to false) will fail.
Comme dit ci-dessus, [[value]] est la valeur que vous attribuez ou at-
tendez de lobjet.
Une propriété ayant « false » comme valeur de l’attribut Enumerable
ne figurera pas dans la liste des propriétés de lobjet, générée avec
for (var in object).
<script type="text/javascript"> "use strict";
// Définition de propriété lors de la création
var obj = {nom:"nomEl",matr:45};
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: {…}
// configurable: true
1 / 19 100%

Propriétés d’objets et leurs attributs - javascript tome xvi

La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !