@@ -12,13 +12,19 @@ anObject = {};
1212// without prototype
1313anObject = Object . create ( null ) ;
1414
15+ // creating with prefilled properties
16+ anObject = {
17+ "key1" : "value1" ,
18+ "key2" : "value2" ,
19+ } ;
20+
1521// assign simple
1622anObject [ "key" ] = "value" ;
1723
1824// assign multiple
1925Object . assing ( anObject , {
2026 "key1" : "value1" ,
21- "key2" : "value2" ,
27+ "key2" : "value2"
2228} ) ;
2329
2430// get a specific value
@@ -45,8 +51,31 @@ Object.entries(anObject).forEach(function ([key, value]) {
4551
4652} ) ;
4753
48- // has
54+ // has a key
4955anObject . hasOwnProperty ( "key" ) ;
5056
5157// has safe, works even when anObject has a key "hasOwnProperty"
5258Object . prototype . hasOwnProperty . call ( anObject , "key" ) ;
59+
60+ // remove a value
61+ anObject [ "key" ] = undefined ;
62+
63+ // completly remove a property (key and value)
64+ delete anObject [ "key" ] ;
65+
66+ // prevent future extensions
67+ Object . preventExtensions ( anObject ) ;
68+ anObject [ "newThing" ] = 2 ; // Error in strict mode
69+
70+ // prevent future extensions and removals
71+ anObject [ "beforeSealing" ] = 10 ;
72+ Object . seal ( anObject ) ;
73+ anObject [ "newThing" ] = 2 ; // Error in strict mode
74+ delete anObject [ "beforeSealing" ] ; // Error in strict mode
75+
76+ // prevent future extensions and removals and mutations
77+ anObject [ "beforeSealing" ] = 10 ;
78+ Object . freeze ( anObject ) ;
79+ anObject [ "newThing" ] = 2 ; // Error in strict mode
80+ delete anObject [ "beforeSealing" ] ; // Error in strict mode
81+ anObject [ "beforeSealing" ] = 11 ; // Error in strict mode
0 commit comments