jQuery.extend & callback
Blogs20132013-10-19
jQuery.extend & callback
Here is my simple example to use jQuery.extend to add params and callback function.
jQuery.fn.threeColumns = function(params, callback) {
var opts = {
fsize_step: 2,
//will use for element.css(opts.adjust_box());
adjust_box: function() {
return {
'margin': '20px',
'padding': '20px',
'height': 'auto'
}
}
};
jQuery.extend(opts, params);
if(typeof opts.adjust_box === 'function') {
console.log(opts.adjust_box());
}
callback(opts);
}
$('div.container').threeColumns({a:'b'}, function(params){
console.log(params);
});
//Will display:
Object { margin="20px", padding="20px", height="auto"}
Object { fsize_step=2, a="b", adjust_box=function()}