I am writing a jQuery plugin and need functions that can be called from inside as well as outside the plugin. Here is my code so far:
(function($){
$.fn.bxSlider = function(options){
var defaults = {
mode : 'horizontal',
speed : 500
}
var options = $.extend(defaults, options);
var base = this;
this.each(function(){
var someText = base.getText;
console.log(someText);
});
this.getText = function(){
return base.children().text();
}
return this;
}
})(jQuery);
When I call getText() from outside the plugin - it works just fine:
$(function(){
var slider = $('ul').bxSlider();
var text = slider.getText();
$('body').append(text);
});
But when I try to call the function inside the plugin, I get a "function is not defined" error. Am I using the wrong syntax?
Thanks!