On Mon, Feb 7, 2011 at 15:45, Fran <[email protected]> wrote:

>  Hi Morgan,
>
> well, I found something interesting about using jQuery and its event
> system. I noticed that by binding events to the object prototype like this:
> $(MyClass.prototype).bind('namespace.myevent'), I can trigger those events
> from within the instance like this: $(this).trigger('namespace.myevent'). I
> find this really useful, at least for the project I'm working on. Here is
> the idea:
>
> /* @Class */
> var MyClass = function () {...};
>
> /* @Members */
> MyClass.prototype.methodThatTriggersAnEvent = function () {
>
>     //...
>     $(this).trigger('myevent', [...]);
>     //...
>
> }
>
> /* @Events */
> $(MyClass.prototype).bind({
>
>     myevent : function (e, params) {
>         // e.target: MyClass instance
>     }
>
> });
>

I did something related in my current project but without prototype, I used
a simple literal pattern.

Example : http://jsfiddle.net/TLQPy/3/

Regards,

Loic

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to