3

How to implement __get __set PHP in Javascript?

zloctb
  • 10,592
  • 8
  • 70
  • 89

1 Answers1

3

Object.defineProperty with apprpriate parameters.

Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592
  • Perfect!! Note compatibility with older IE browsers <= 8 is limited or non existent. – payling Jun 21 '13 at 16:54
  • 4
    This is not the same thing as the PHP __get and __set magic methods, as it required the getter and setter be defined on a named property, the magic methods in PHP are specifically useful for setting getters and setters when the property does not exist. – Trey Dec 22 '15 at 15:27