Adding a method to String class via Prototype using prototype.__defineGetter__ - Javascript Object

Javascript examples for Object:prototype

Description

Adding a method to String class via Prototype using prototype.__defineGetter__

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {/*from   ww w.j ava  2  s.c  om*/
   String.prototype.__defineGetter__("world", function() {
        return this + ' world';
   });
console.log("hello".world);
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials