here code:
var person = { name: 'greg', year: 20 }; object.defineproperties(person, { gender :{ value: 'male' }, edition : { value : 12 }, edition : { set:function (no) { if (no===13) { console.log('yes') }; } } }) console.log(person.edition)
looks did right, did not change descriptors ideas? thanks
when write person.edition
, calling method. not defined. call set method need assignment
. try this:
var person = { name: 'greg', year: 20 }; object.defineproperties(person, { "gender" :{ value: 'male' }, "edition" : { value : 12 }, "edition" : { set:function (no) { if (no===13) { console.log('yes') }; } , get:function () { return "hi"; } } }) console.log(person.edition) person.edition = 13;
Comments
Post a Comment