Javascript examples for jQuery Method and Property:proxy
Enforce the context of the "test" function
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ test = function(){/*from w w w .j a va2 s . co m*/ this.txt = "property"; $("div").click($.proxy(this.myClick, this)); }; test.prototype.myClick = function(event){ console.log(this.txt); console.log(event.currentTarget.nodeName); }; var x = new test(); }); </script> </head> <body> <div>This is a div element.</div> </body> </html>