Set jQuery JavaScript function scope
How to change the function scope in jQuery event handlers – Edit content (add a revision)
`section(title:'Changing the function scope') `section(title:'Prerequisites') You have to have a basic idea of `tutorial(name:'Event handling in JavaScript'), and specifically `tutorial(name:'Event handling in jQuery') `section(title:'Event Handling') When a handler is executed in JavaScript, the "this" value inside it is equal to the object it's being associated with. In some libraries such as Prototype.js, we have the option of using the bind() method to alter the function in such a way that the value of "this" is whatever we wish. See the prototype.js `a(content:'documentation on bind()' href:'http://www.prototypejs.org/api/function/bind'). This way, we can customize the scope in which a function runs. In jQuery, however, this option doesn't exist. The workaround is to pass parameters through the event object, using the "data" parameter of the event `a(href:'http://docs.jquery.com/Events/bind' content:'bind()') function.
Save as new Revision
Syntax docs