Skip to content Skip to sidebar Skip to footer

Is There A Way To Create A Global Setter?

What I need is to have a function, which is called every time an assignments is performed, so for example when there is : var a = b; c = d; // or even for(var i=3...){} I co

Solution 1:

Is there a way to create a global setter?

No.

ECMAScript2015 introduces Proxy objects which allows you to do "meta programming" but it doesn't work the way you want.

The Proxy object is used to define custom behavior for fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc).


Solution 2:

Object.defineProperty(window, "varname", {set : callbackfunction}}; is the way to go link


Post a Comment for "Is There A Way To Create A Global Setter?"