How to implement __get __set PHP in Javascript?
Asked
Active
Viewed 1,784 times
3
-
[What have you tried](http://whathaveyoutried.com)? What have you looked into? – UnholyRanger Feb 28 '13 at 19:58
-
Can you add some greater detail? – JBone Feb 28 '13 at 19:58
-
1The question was closed as "not a real question" but I think it's legit but duplicate. Start looking for your answer here: http://stackoverflow.com/questions/6985582/monitor-all-javascript-object-properties-magic-getters-and-setters – Tihauan Feb 28 '13 at 20:04
-
unbanned me, please . – zloctb Nov 25 '13 at 11:30
1 Answers
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
-
4This 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