Javascript examples for Object:Object Property
Using Object.defineProperty to define property
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=( function() {/*from w ww . jav a2 s .c o m*/ function myClass(id) { this.em = document.getElementById(id); Object.defineProperty(this, 'html', { set: function(val) { console.log('Set to ' + val); } }); } (new myClass('foo')).html = 'bar'; }); </script> </head> <body> </body> </html>