addyosmani / essential-js-design-patterns

Repo for my 'Learning JavaScript Design Patterns' book
http://addyosmani.com/resources/essentialjsdesignpatterns/book/
4.8k stars 791 forks source link

Issue in Object Creation Section #204

Open divyanshu-rawat opened 7 years ago

divyanshu-rawat commented 7 years ago

There are four ways in which keys and values can then be assigned to an object. Here in 4th case I am encountering a problem when I console the newObject then it returns an empty object but why so ? I am using node v7.3.0


// 4. Object.defineProperties

// Set properties
Object.defineProperties( newObject, {

  "someKey": {
    value: "Hello World",
    writable: true
  },

  "anotherKey": {
    value: "Foo bar",
    writable: false
  }

});

screenshot from 2017-01-07 17 08 16

dancrumb commented 4 years ago

The property descriptor includes an enumerable key that must be set to true if you want to see it when you print the object to the console.

Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty