0

I'm looking for the method that Object or Array use internally when executing:

var x = { a: 1 }
// getters
x['a'] // or x.a
// setters
x['a'] = 1 // or x.a = 1

Same for arrays

var a = [0, 1]
// getter
a[0]
// setter
a[0] = 1
carlesba
  • 3,106
  • 3
  • 17
  • 16

1 Answers1

2

Well, you have two alternatives:

  • defineProperty contains "set" and "get" attributes. You could apply this thing for every property that you need to be declared.
  • Using proxies (requires ecmascript 6) you can declare a getter and a setter and this will be applied for every property.
fcortes
  • 1,338
  • 3
  • 11
  • 26
  • Pardon me for being pedantic about terminology, but in JavaScript/ECMAScript members of objects are called "properties", not "attributes". An Attribute is something else completely: http://www.ecma-international.org/ecma-262/6.0/#sec-attribute – Dai Feb 28 '16 at 21:03
  • Good Point @Dai. I fixed that, thanks for your feedback! – fcortes Mar 03 '16 at 13:35