I have some Javascript code in an external file, and It’s going to be for people to use on their own sites… so I want some way for them to be able to pass in multiple options… how would I do this?
Sorry, more information:
I would give them html + script + css to load:
<div class="mywidget"></div>
<script src="app.js"></script>
<link rel="stylesheet" type="text/css" href="style.css" />
And in the script (some of the code):
var App = {
init: function(){
/* ----------------------------
On initialization....
---------------------------- */
App.doStuff(), App.doMoreStuff();
},
doStuff: function(){
alert('hi');
}
}
So I basically want them to be able to customize how my app works… so let’s say I want them to customize the alert, or any other amount of things.
A standard solution (used for example by jQuery), is to receive as argument in your function (or configuration function) only one argument, handled as a map :
In this case, the user may call
veryFreeFunction();orveryFreeFunction({b:"test"});. He will pass only the parameters he needs.