Hi,

> new myPlugin.('div1',{callback:function(){ ... }});

I'm assuming you have a typo in that (with the dot after "myPlugin",
it's invalid syntax).

But assuming you have something like:

    function myPlugin(selector, options) {
    }

...or effectively the same thing via Class.create, then you need to
remember your options or callback somewhere. I'll assume you're just
going to keep all the options around, something like this:

    function myPlugin(selector, options) {

        this.options = options;
    }

You can then call the function just like any other function (because
that's what it is) -- so for instance, passing in three arguments:

    this.options.callback("one", "two", "three");

If you need to set the context (the `this` value within the call) to
something specific, you'd typically use Function#call or
Function#apply, which are built-in Javascript features. The only
difference between them is how you specify the arguments to pass the
function; for #call, you pass them as individual arguments, with
#apply you pass them as an array. Either way, the function receives
them as individual arguments. So these calls are identical:

    this.options.callback.call(foo, "one", "two", "three");
    this.options.callback.apply(foo, ["one", "two", "three"]);

In each case, `callback` gets called with `this` = `foo` and with
three arguments, "one", "two", and "three".

HTH,
--
T.J. Crowder
Independent Software Consultant
tj / crowder software / com
www.crowdersoftware.com


On May 11, 3:46 pm, Phonethics <phoneth...@gmail.com> wrote:
> Im trying to create a plugin where one of the options is a callback
> parameter
>
> new myPlugin.('div1',{callback:function(){ ... }});
>
> But how do I invoke the callback in the plugin ?
> this.options.callback();
>
> ?
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Prototype & script.aculo.us" group.
> To post to this group, send email to prototype-scriptacul...@googlegroups.com.
> To unsubscribe from this group, send email to 
> prototype-scriptaculous+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/prototype-scriptaculous?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to