There is a function that requires and setting object.
var opt = {
height: 300,
maxLength: 4000,
valueChangeEvent: "change",
placeholder: "",
}
$(selector1).doStuff(opt);
$(selector2).doStuff(opt);
$(selector3).doStuff(opt);
$(selector4).doStuff(opt);
The thing is that the placeholder should be different every time. Currently, I create this opt object with every call but it seems ugly. Is there a way to pass this opt object while just changing one property?
You can use your opt
object as a template like this
$(selector1).doStuff({...opt, placeholder: 'different every time' })
The ...
operator destructures the original opt
object, then any further other properties are added to the result, replacing anything that conflicts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With