문제

I want to provide a way to use an on-event handler from the outside of a plugin. Problem is, that the trigger will not fired if I provide them in wrong order.

For example, this works:

$(window).on('foo:bar', function(){
    alert(true);
});
$(window).trigger('foo:bar');

...this, however does not:

$(window).trigger('foo:bar');
$(window).on('foo:bar', function(){
    alert(true);
});

Any ideas how the second approach can work?

Update

Here it works: http://www.benplum.com/projects/rubberband/

도움이 되었습니까?

해결책

You cannot. You want to eat cake before baking it.

UPD: You're misinterpreting the code at http://www.benplum.com/projects/rubberband/

Here is a jsfiddle with proof that it doesn't work like you're thinking: jsfiddle.net/zerkms/z5Mya/

Note about code: I've forked the library and added trivial console.log here: https://github.com/zerkms/Rubberband/blob/master/jquery.bp.rubberband.js#L77

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top