jquery - Private method returned as string -
i'm developing simple jquery plugin , im having difficulties setting method structure. please enlighten me. using plugin structure described in official jquery authoring documentation.
the problem having when calling private function _generateid, function returns function text ( function() { return this.. ) instead of '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 + ' not exist on jquery.workzone' ); } }; })( jquery );
you must call function parentheses methods._generateid().
Comments
Post a Comment