underscore optional params

by abenrob

HTML

Without Parameter:<br>
<span id="without"></span><br>
With Parameter:<br>
<span id="with"></span>

JavaScript

var options = {
    desc: 'concise info'
};
test = function(options){
    options = options || {};
    var defaults = {
        id: 123,
        desc: 'this is information',
        tag: 'uncategorized'
    };
    var options = _.extend(defaults,options);
    return JSON.stringify(options);
}
document.getElementById('without').innerHTML = test();
document.getElementById('with').innerHTML = test(options);