I recently picked up a book at Singapore’s National Library. The title is Expert JavaScript.
The book starts with a chapter explaining about the concept of object in JavaScript. The opening chapter really blows my mind. Below code is familiar to me:
//create object var animal = {}; //define property animal.legs = 4;
But I don’t know that I can configure the properties as below:
var animal= {}; Object.defineProperty(animal, 'legs', { writable: true, configurable: true, enumerable: true, value: 4 }); Object.defineProperty(animal, 'ears', { writable: true, configurable: true, enumerable: true, value: 2 }); Object.defineProperty(animal, 'secretTrackerEnabled', { enumerable: false, value: true }); for (var x in animal) { console.log(x); } // => legs // => ears
Seriously, this book is really good. It only only took me one chapter to realize how I have missed so much of JavaScript’s core concept.
loading...
About Hardono
Incoming Search
javascript