Я разрабатываю простой плагин jquery, и у меня возникают трудности с настройкой структуры метода. Может ли кто-нибудь, пожалуйста, просветить меня. Я использую структуру плагина, как описано в официальной документации Jquery Authoring.
Проблема, с которой я сталкиваюсь, заключается в том, что при вызове закрытой функции _generateID функция возвращает текст функции (function () {return this ..) вместо hi.
(function( $ ){
var methods = {
init : function( options ) {
return this.each(function() {
});
},
_generateID : function() {
return this.each(function() {
return 'hi';
});
},
create : function( options ) {
return this.each(function() {
var settings = {
'id' : methods._generateID,
};
if ( options ) { $.extend( settings, options ); }
$('<div>', {
id : settings.id,
}).appendTo(this);
});
},
destroy : function( id ) {
return this.each(function(){
$(window).unbind('#'+id);
$('#'+id).remove();
});
}
};
$.fn.workzone = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.workzone' );
}
};
})( jQuery );