Javascript examples for Object:Object Property
Use "this" inside a function passed to __defineGetter__
<html> <head></head> <body> <p>Open the JavaScript console to see the output.</p> <script> Object.defineProperty(String.prototype, "foo", { get: function() {/*from ww w . java 2s . c o m*/ // Here, `this` is the string return this.toUpperCase(); } }); console.log("hi there".foo); </script> </body> </html>