Use classes.
class Console {
log(...args) {
console.log(...args);
return this;
}
warn(...args) {
console.warn(...args);
return this;
}
error(...args) {
console.error(...args);
return this;
}
}
const con = new Console();
con
.log("Hello")
.warn("You really shouldn't do that")
.error("Danger!");
Or if you're stuck with ES5:
var con = {
log: function () {
console.log.apply(console, arguments);
return this;
},
warn: function () {
console.warn.apply(console, arguments);
return this;
},
error: function () {
console.error.apply(console, arguments);
return this;
}
};
con
.log("Hello")
.warn("You really shouldn't do that")
.error("Danger!");