browse by category or date


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.

About Hardono

Hi, I'm Hardono. I am working as a Software Developer. I am working mostly in Windows, dealing with .NET, conversing in C#. But I know a bit of Linux, mainly because I need to keep this blog operational. I've been working in Logistics/Transport industry for more than 9 years.

No Comment

Add Your Comment