Does jquery have the equivalent of dojo.connect ()?

Forgive my ignorance as I am not so familiar with jquery. Is there an equivalent to dojo.connect ()?

I found this solution: http://think-robot.com/2009/06/hitch-object-oriented-event-handlers-with-jquery/

But the mute function is disabled!

Do you know another solution in jquery? There is jquery.connect, but this plugin does not work in my tests.

Thanks for your help,
Stephane

+4
source share
4 answers

What do you mean by dojo.connect () equivalent?

If you want to create your own event handlers, look at bind (), trigger (), and proxy () in Events .

The proxy () function will force you to override what your callback function indicates.

+2
source

The closest equivalent to jQuery has .bind() , for example:

 $("#element").bind('eventName', function(e) { //stuff }); 

And .unbind() remove the handler, for example:

 $("#element").unbind('eventName'); 

There are also shortcuts for .bind() , so, for example, click can be done in two ways:

 $("#element").bind('click', function() { alert('clicked!'); }); //or... $("#element").click(function() { alert('clicked!'); }); 

There is also .live() ( .die() to untie) and .delegate() ( .undelegate() to untie) for bubbling-based event handlers rather than direct attachments, like dynamically generated elements.

The examples above were anonymous functions, but you can provide the function directly, like dojo (or any javascript), for example:

 $("#element").click(myNamedFunction); 
+3
source

It is not, but you can achieve the same:

 $('#someid').click(function() { SomeFunc($(this)) }); 

This will cause somefunc to pass, to the click event of the control with id "someid". When the control is clicked, the function will be called, and the parameter will be a jquery object that refers to the control that was clicked.

Update I just did some research and think . delegate () is closer to what you want.

+1
source

jQuery connect is equivalent to dojo.connect.

+1
source

Source: https://habr.com/ru/post/1310647/


All Articles