javascript call a function of a plugin in instantiating it -
i want call function in plugin.
i overloaded function want call function it.
$("myselector").myplugin({ my_function : function (){ functioin_from_the_plugin(); } });
an error appears says "unknown function".
either plugin allows hookup startup event (e.g. oninit in following, plugin-specific name),
e.g.
$("myselector").myplugin({ oninit: function (instance){ instance.function_from_the_plugin(); } });
or (if plugin retains correct this
when calling method):
$("myselector").myplugin({ oninit: function (){ this.function_from_the_plugin(); } });
or, have wait plugin created before calling method.
depending on way created plugin, usual way (which uses string specify function name call):
$("myselector").myplugin().myplugin("function_from_the_plugin");
this creates plugin, attaches element, calls method on plugin.
note: without seeing code plugin, these suggestions. plugin pattern brain-dead , don't allow function calling
Comments
Post a Comment