How do I invoke a private method from a public one and vice versa if I follow the plugin authoring guide?
I usually declare the private methods within the init method like:
var methods = {
init: function(options) {
var settings = $.extend({
}, options);
return this.each(function() {
var $this = $(this);
var data = $this.data('griffin-editor');
this.trimSpaceInSelection = function () {
//how do I call a public method here?
//to get the this context correct.
}
if (typeof data !== 'undefined') {
return this;
}
//the rest of the code.
It might be the incorrect thing to do?
If by ‘this context correct’ you mean that you want call some public method with this set to value which this has inside trimSpaceInSelection then you can do it like this:
And if you want set this inside public method to current jQuery collection then: