Note that isFunction is much faster now. It has been improved 3 times
between 1.2.6 and 1.3b.

On Thu, Dec 25, 2008 at 4:06 PM, Eduardo Lundgren <eduardolundg...@gmail.com
> wrote:

> Hi Balazs,
>
> Thanks for give us your opinion.
>
> When you use $.isFunction(data) on the bind method it is very expensive
> when you have a lot of iterations.
>
> Diff the file I attached with the original file (rev. 5996) I made only a
> small change on the bind() method, and it's compatible with data and with
> out API.
>
>
>
> On Thu, Dec 25, 2008 at 3:05 AM, Balazs Endresz 
> <balazs.endr...@gmail.com>wrote:
>
>>
>> Hi, I think this would be really useful! I've also modified jQuery to
>> do this a while ago (1.2.6) but with the new scope being the last
>> argument, so it works without the data object as well:
>>
>> jQuery.fn.bind=function( type, data, fn, bind ) {
>>                return type == "unload" ? this.one(type, data, fn) :
>> this.each
>> (function(){
>>                        if( $.isFunction(data) )
>>                                jQuery.event.add( this, type, data, bind,
>> fn );
>>                        else
>>                                jQuery.event.add( this, type, fn, data,
>> bind );
>>                });
>>        }
>>
>>
>> jQuery.event = {
>>        add: function(elem, types, handler, data, bind) {
>>                if ( elem.nodeType == 3 || elem.nodeType == 8 )
>>                        return;
>>
>>                if( bind != undefined )
>>                        handler = jQuery.bind(handler, bind); //change
>> scope
>> ...
>>
>>
>> jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
>>
>>  "mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,"
>> +
>>        "change,select,submit,keydown,keypress,keyup,error").split(","),
>> function(i, name){
>>
>>        // Handle event binding
>>        jQuery.fn[name] = function(fn, bind){ //second argument for the
>> scope
>>                return fn ? this.bind(name, fn, bind) : this.trigger(name);
>>        };
>> });
>>
>> where jQuery.bind is:
>>
>> jQuery.bind=function( fn, bind ){
>>        var args = $.makeArray( arguments ).slice(2);
>>        if( args.length == 1 && $.isArray( args[0] ) )
>>                args = args[0];
>>        return function(){
>>                return fn.apply( bind, args );
>>        }
>> }
>>
>>
>>
>> On Dec 25, 10:38 am, "Eduardo Lundgren" <eduardolundg...@gmail.com>
>> wrote:
>> > 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:
>> >
>> > var scopeTest = function() {
>> >                 this.name = "iamanotherscope";
>> >
>> >                 this.internalHandler = function(event) {
>> >                     console.log("I am another scope method.", this.name
>> ,
>> > event, event.data);
>> >                 };
>> >             };
>> >
>> >             var scope = new scopeTest();
>> >
>> >  $('div').bind('click', {data: true}, globalHandler);
>> >             $('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.
>> >
>> > --
>> > Eduardo Lundgren
>> > Software Engineer
>> > Liferay, Inc.
>> > Enterprise. Open Source. For Life.
>> >
>> >  event.js
>> > 26KViewDownload
>
>
>
>
> --
> Eduardo Lundgren
> Software Engineer
> Liferay, Inc.
> Enterprise. Open Source. For Life.
>
> >
>


-- 
Ariel Flesler
http://flesler.blogspot.com

Reply via email to