- inline get/set are OK
- they're not deprecated if favor of
defineProperty
(__defineGetter__
and__defineSetter__
are deprecated) defineProperty
gives to you more granularity and control over the property you're going to define: you can decide if the property isconfigurabile
,writable
andenumerable
. You can't do that withget
andset
. In addition, withdefineProperty
you could not define necessary a getter or a setter, but just a value.- Use
get
andset
when you do not need more granularity, it's a sugar syntax, and can be used in the object definition itself, wheredefineProperty
has to be used once the instance is created. UsedefineProperty
when you need more granularity, or you do not need necessary to specify getter and setter but just a value.
Hope it helps.
Links to the specs about get
and set
ES5: http://www.ecma-international.org/ecma-262/5.1/#sec-11.1.5
ES6 (draft): http://people.mozilla.org/~jorendorff/es6-draft.html#sec-method-definitions-static-semantics-propname