Closed neojski closed 11 years ago
In fact, it's not even working as config
was never defined.
Confirmed. Looking into this now.
Should fix:
// If the above feels a little difficult to read, a short-hand could
// be written as follows:
var defineProp = function ( obj, key, value ){
var config = {
value: value,
writable: true,
enumerable: true,
configurable: true
};
Object.defineProperty( obj, key, config );
};
// To use, we then create a new empty "person" object
var person = Object.create( null );
// Populate the object with properties
defineProp( person, "car", "Delorean" );
defineProp( person, "dateOfBirth", "1981" );
defineProp( person, "hasBeard", false );
console.log(person);
// Outputs: Object {car: "Delorean", dateOfBirth: "1981", hasBeard: false}
Yup, this looks much better. I just didn't make a PR with this solution as I didn't know if you just forgot config
or I missed something.
This is actually duplicate of #81.
Thanks! It was entirely my fault :) I'll apply a patch for this soon. Thanks for noticing the dupe!
Have a look at mdn defineProperty. It looks like
defineProp
is not really the shorthand for that above code in the book.Reason: default values for
writable
,enumerable
andconfigurable
isfalse
.