I'm implementing a simple toast notification system using JS. This is my code:
const notify = {
success(text) {
this.show("success", text);
},
error(text) {
this.show("error", text);
},
show(type, text) {
}
};
notify.success("Done!");
notify.error("Something went wrong");
Is it really necessary to create the first two methods (success and error), or there's a way to know which of them has been invoked and then pass it as an argument (type) to show method? I mean something like this:
const notify = {
type: this.called,
text: type(text),
show(type, text) {
}
};
What I have tried:
const notify = {
type: this.called,
text: type(text),
show(type, text) {
}
};