Reputation: 6335
Hello I am writing some jquery usefuls plugins, but I am asking where should I put the defaults settings object in the code. example Here i put them inside the init method:
(function($)
{
var methods =
{
init : function(options)
{
var settings = {
'images3dPath' : '',
'imagesZoomPath':'',
..................
};
Or I should put them at the top of the plugin:
(function($)
{
var settings = {
'images3dPath' : '',
'imagesZoomPath':'',
..................
};
var methods =
{
init : function(options)
{
In this moment I am using the first solution, but I am not sure of that. Any one has any idea?
Upvotes: 2
Views: 186
Reputation: 169421
It's important to make you default settings on the same level as your function that takes options
so that there a local variable unique to each call of your plugin rather then a static global list of settings.
It's just my options
function tends to be an outer one.
I have
var globalDefaults = { ... };
var methods = {};
methods.init = function(options) {
...
var settings = { ... };
$.extend(true, settings, options);
...
};
Upvotes: 3