I\'ve created a class and I would like to set some default options for values in case the user does not supply any arguments. I recently went from a constructor that took mu
If you want to change to a configuration pattern, you can still keep your default parameter syntax:
module.exports = class User {
constructor({ name = "Joe", age = 47 } = {}) {
this.name = name;
this.age = age;
}
}
const User = require("./user");
const user = new User(); // Defaults to "Joe" and 47