make sure 'this' refers to the object literal within the object literal - Javascript jQuery

Javascript examples for jQuery:Plugin

Description

make sure 'this' refers to the object literal within the object literal

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
  <script type="text/javascript">
    $(window).load(function(){//from  ww w .j  a  v a2s . c  o m
var obj = {
    a: function() { return 2 },
    b: function() { return 5+ this.a() },
}
$('#hey').text( $.proxy(obj.b, obj) );
    });

      </script> 
 </head> 
 <body> 
  <div id="hey"></div>  
 </body>
</html>

Related Tutorials