File tree Expand file tree Collapse file tree
25_Revision/19_oops_and_classes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // object property handle
2+
3+ let pi = Math . PI
4+ console . log ( pi ) // 3.141592653589793 it is default value
5+
6+
7+ let piObj = Object . getOwnPropertyDescriptor ( Math , "PI" ) // it is a method of object property show method
8+ console . log ( piObj )
9+ /*
10+ {
11+ value: 3.141592653589793,
12+ writable: false,
13+ enumerable: false,
14+ configurable: false
15+ }
16+ */
17+
18+ let myNewObj = Object . create ( { } )
19+ console . log ( myNewObj )
20+
21+ myNewObj . courseName = "JavaScript"
22+ myNewObj . price = 499
23+ myNewObj . instructor = "SujitTomar"
24+
25+ console . log ( myNewObj )
26+ console . log ( Object . getOwnPropertyDescriptor ( myNewObj , "price" ) ) ;
27+ // { value: 499, writable: true, enumerable: true, configurable: true }
28+
29+ Object . defineProperty ( myNewObj , "price" , {
30+ writable : false ,
31+ enumerable : false ,
32+ configurable : false
33+ } )
34+
35+ console . log ( Object . getOwnPropertyDescriptor ( myNewObj , "price" ) ) ;
36+ // { value: 499, writable: false, enumerable: false, configurable: false }
Original file line number Diff line number Diff line change 1+ let course = {
2+ courseName : "JavaScript" ,
3+ prince : 899 ,
4+ teacher : "tomar"
5+ }
6+ /* function create in object */
7+ course . buyCourse = function ( ) {
8+ console . log ( "Code Fat Gaya ese hi bolte hai😊" )
9+ }
10+
11+ // in this case you give a return function that is problem
12+ for ( let [ key , value ] of Object . entries ( course ) ) {
13+ console . log ( `${ key } : ${ value } ` ) ;
14+ }
15+
16+ /*
17+ courseName : JavaScript
18+ prince : 899
19+ teacher : tomar
20+ buyCourse : function(){
21+ console.log("Code Fat Gaya ese hi bolte hai😊")
22+ }
23+ */
24+
25+ // in this case you get better result
26+ for ( let [ key , value ] of Object . entries ( course ) ) {
27+ if ( typeof value !== 'function' ) { // here you pass function in string case
28+ console . log ( `${ key } : ${ value } ` ) ;
29+ }
30+ }
31+
32+ /*
33+ courseName : JavaScript
34+ prince : 899
35+ teacher : tomar
36+ */
You can’t perform that action at this time.
0 commit comments