如果我遵循plugin authoring guide,如何從公共方法調用私有方法,反之亦然?調用插件方法
我通常聲明init
方法像內的私有方法:
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.
這可能是不正確的事是什麼?
爲什麼它與插件指南有什麼不同?這可能會幫助http://stackoverflow.com/questions/6420825/call-private-method-from-public-method – elclanrs 2012-02-21 07:34:46
@elclanrs:看到我的更新。 – jgauffin 2012-02-21 07:47:15
我明白了......我正在找東西。這些可能有所幫助,[1](http://stefangabos.ro/jquery/jquery-plugin-boilerplate-revisited/),[2](http://stackoverflow.com/questions/2061501/jquery-plugin-design- pattern-common-practice-for-dealing-with-private-functio),[3](http://www.virgentech.com/blog/2009/10/building-object-oriented-jquery-plugin.html) – elclanrs 2012-02-21 08:07:23