With `arguments.callee deprecated I would like to find al alternative approach to extend a jQuery plugin I created to execute one of its built in methods from the outside.
My sample jQuery plugin:
(function($) {
$.myPlugin = function(options) {
// normal var and methods
// this is to execute a method from outside
arguments.callee.close = function() {
// to do when this is called
}
}
}(jQuery))
The plugin would be used for it’s normal use with this
$(selector).myPlugin();
And this is to trigger the “close” method inside the plugin
$(selector).myPlugin.close()
I found an answer to this and have this to share:
(function($) {
function myPlugin(options) {
// normal var and methods: do whatever I want...
myPlugin.close = myPlugin.close.bind(this);
}
myPlugin.close = function() {
// do this thing
}
$.fn.myPlugin = myPlugin;
}(jQuery));
This allows me to call the close method with this:
$(selector).myPlugin.close();