https://bugzilla.wikimedia.org/show_bug.cgi?id=23580

--- Comment #8 from Michael Dale <[email protected]> 2011-08-29 07:28:18 UTC ---
The bind trigger system is widely used for pure JS objects, so I don't think
jQuery will ever disallow it. For example if you google the concept you see
lots of folks recommending it.

But I do agree it can result in some strange gotchas and edge cases that may
not be ideal and we should not do it "just because it works and other say to do
it". 

A more traditional hook system may be more correct.

While jQuery does not officially "accept pure JS" objects its inherent in the
model of loose typing that jQuery is designed around. i.e you can illustrate
this with much more evil things like: 

var o = {};
$(o).css('width', 10);
console.log(o.width);

// Output:
10px

If we were to write a hook system it should share the nifty features of the
jQuery one. Like namespaced bind add and removal, being able to pass in an
array of objects to be binded, some concept of inheritance of same named local
methods as the trigger, a convenience function to setup the hook system
on-demand so that binds and triggers have no negative consequences if either
does not exist etc.

In essence everything the jQuery bind / trigger system does. You can think of
it as a plugin. We can always just override jQuery.fn.bind to guarantee pure JS
object paths behavior predictably into the future. 

It comes down to semantics and clarity of intent of any given developer. Does
it add syntactical clarity to be able to treat the bind trigger concept the
same across objects or does it muddle things that it works the same? 

If it can save time and code to share the concept across objects then that’s
good, if it will confuse people and take away flexibility then that’s bad. 



Some examples of gotchas for jQuery base bind / trigger

var o = {length: 3};
$(o).bind( 'custom', function(){ console.log('hi') } );
$(o).trigger('custom');

// Output
hi
hi
hi 

Of course this can be a "feature" if you have an array of objects that you want
to bind events to. 

Also a "feature" of the binding mechanism includes calling the child method
i.e:

var o = {change: function(){ console.log('hi method')} };
$(o).bind( 'change', function(){ console.log('hi bind') } );
$(o).trigger('change');

// Output
hi bind
hi method

Which can be tricky / non-ideal if you don't know about that.

-- 
Configure bugmail: https://bugzilla.wikimedia.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to