$.fn.demo = function(options) {
var defaults = {
opacity: 50,
width: '250px',
height: '100px',
color: 'red'
}
}
Is there any way to conditionally pass options to a function, like such:
$().demo({
opacity: 60,
if (div.length){
width: '350px'
}
height: '100px'
});
Just curious what would be the best way to handle a situation where you may want to pass different options depending on circumstances. Thanks!
If it’s simple enough you can use the ternary operation
If it’s more complicated you should just compose the parameter object outside of the function call.