For better code ES6, is good to use destructure to avoid duplicaton, right?
So, how I use same params
and options
in other functions, inside Class
?
Example like:
const params = [
title,
text,
confirm,
buttonConfirm || "Ok",
buttonCancel || "Cancel",
];
const options = {
title: params.title,
text: params.text,
confirmButtonText: params.buttonConfirm,
cancelButtonText: params.buttonCancel,
showCancelButton: Boolean(params.confirm),
};
class Alert {
success(...params) {
alertPlugin({
...options,
type: "success",
}).then(
() => params.confirm()
);
},
error(...params) {
alertPlugin({
...options,
type: "error",
}).then(
() => params.confirm()
);
},
warning(...params) {
alertPlugin({
...options,
type: "warning",
}).then(
() => params.confirm()
);
}
}
export default Alert;
And I call method with this code:
this.$alert.success({
"Title custom",
"Description custom",
this.callbackSuccess,
"Yeah!",
"Noo!",
});