jQuery plugin function in global scope -
nowadays have been learning lot jquery plugin development , jquery . have made simple jquery plugin moved outside initialize() function $.fn.testplugin initialize() function in global scope. question how move outside initialize() function $.fn.testplugin same time make local scope.
plugin:
(function($){ function initialize($obj, color){ $obj.css("color",color); }; $.fn.testplugin = function(options){ var defaults = { color: "red" }; var option = $.extend(defaults, options); return this.each(function(){ var $this = $(this); initialize($this, option.color); }); }; })(jquery);
your initialize() function not in global scope; explicitly creating closure defined. cannot access initialize() function outside outermost function in posted code.
Comments
Post a Comment