If I want to give a variable a a property P (non-accessor property) and I do not care if it’s configurable/enumerable/writable.
I can be 100% sure it is in fact more beneficial (in all ways you can think of) to simply do a
a.P=value // or
a["P"]=value
instead of using
Object.defineProperty
So basically as a rule, we should not touch that Object.defineProperty unless we need to create accessors and/or we want to control the configurable/writable/enumerable status of the properties?
I wouldn’t say it’s “more beneficial”, but these are identical in functionality:
Obviously the latter is much more verbose, also much slower (roughly 1,000x slower in Chrome) if you’re defining many properties:
http://jsperf.com/setting-object-properties