Reputation:
I have a plugin that looks like this:
(function($) {
$.fn.plugin_name = function(options) {
var $this = $(this);
var defaults = {
// some defaults
};
options = $.extend({}, defaults, options);
var work = {
action_1: function() {
// do something
},
action_2: function(output) {
alert('hello world');
}
}
that.submit(function(e) {
e.preventDefault();
work.action_1();
});
return $this;
}
})(jQuery);
It's being used like any traditional jquery plugin, by being attached to a page element like so:
$('#search-form').plugin_name({
// overide options
});
My question is, how can I execute the work.action_2()
function that's deeply nested inside the plugin? I would like to call it manually from the javascript console in firebug.
Upvotes: 0
Views: 134
Reputation: 1321
Create it in a separate utility function if its needed independently, better if its in your own global object. So you can call it like so: $.myGlobalObj.action_2()
Upvotes: 0
Reputation: 150253
My question is, how can I execute the work.action_2() function that's deeply nested inside the plugin?
You can't, it's outside of your scope!
you can't reach private function variables, just like you can't reach my functions...
Upvotes: 2