[jQuery] Adding scope support to .bind()
Hi guys,
The .bind() method consider the scope of the handler the element whose the event is assigned - that is the correct as default.
I've been playing with the event.js and implemented an alternative to call .bind(), specifying another scope, that looks useful for our api.
I've attached the event.js modified from the rev. 5996 from the trunk.
The changes are compatible with the current API.
Here goes one example:
<div style="margin-left: 40px;">var scopeTest = function() {
</div> <a href="http://this.name">this.name</a> = "iamanotherscope";
this.internalHandler = function(event) {
console.log("I am another scope method.", <a href="http://this.name">this.name</a>, event, event.data);
};
};
var scope = new scopeTest();
<div style="margin-left: 40px;"> $('div').bind('click', {data: true}, globalHandler);
</div> $('div').bind('click', {data: true}, scope.internalHandler); // handler, data, default scope
$('div').bind('click', {data: true}, scope, scope.internalHandler); // handler, data, pre-defined scope
Let me know if make sense for you.
<br clear="all">
--
Eduardo Lundgren
Software Engineer
Liferay, Inc.
Enterprise. Open Source. For Life.