Javascript examples for Object:this
Extend the Scope of This
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//w ww . ja v a 2s .c om var myObj = { test: "Hello", test2: " World", run: { all: function() { return this.test + this.test2; }, part: function() { return this.test2; } } }; console.log(myObj.run.all.bind(myObj)()); console.log(myObj.run.part.bind(myObj)()); } </script> </head> <body> </body> </html>