Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting additions to a Javascript object's properties

Other than regularly polling for changes, is there any (standard) way to register an event or callback that will be triggered any time a new property is added to a specific object?

like image 860
Alnitak Avatar asked Mar 17 '11 13:03

Alnitak


2 Answers

Simply put, the answer is no.

Mozilla's JavaScript implementation has an overload for unresolvable methods, but it doesn't work for standard properties, see __noSuchMethod__. Of course, you asked for a standard method and no other implementations support this as far as I'm aware.

like image 55
Andy E Avatar answered Sep 19 '22 03:09

Andy E


Once upon a time, ActionScript supported the __resolve property. As far as I know, JS has no similar crossbrowser construct, but maybe you could simulate it with some simple (but still bloaty) accessor function, like this:

http://bytes.com/topic/javascript/answers/789987-does-javascript-support-some-kind-__resolve-method

like image 28
biziclop Avatar answered Sep 20 '22 03:09

biziclop