In JScript, is it possible to implement getters and setters that look like properties of an object outside?

When trying to connect and generally play with some non-browser, I came across getters and setters that looked like normal properties of an object. Something like that:

js> var o = { a: 4, get b(){ return this.a + 3; }, set b(val){ this.a = val - 3; } }; js> oa 4 js> ob 7 js> ob=10 10 js> oa 7 

This seems to work in the latest versions of Rhino and Spidermonkey, but is it possible to implement or simulate the behavior (the definition syntax is less important to me) in JScript (Windows Script Host)?

+4
source share
3 answers

Answer No Setters and getters are just properties that act as functions, but there is no way to correctly emulate the syntax. I had a semi-semantic concept of emulating getters and setters on HTML elements in <= IE7 using behavior, but even this turned out to be more complicated than I had previously thought. Even IE8 only supports getters / setters on DOM objects, not JScript objects, so I think they need to enable the JScript command if they ever will.

If only someone had thought to include setters and getters in the original JScript / ECMAScript implementations.

+1
source

According to this article (by John Resig, creator of jQuery), Javascript recipients and setters are supported in JScript.NET 8.

0
source

This is a complete list of browsers and their support for getters and setters. http://robertnyman.com/javascript/#javascript-getters-setters-object-defineproperty-compatibility

0
source

All Articles