Skip to content

Instantly share code, notes, and snippets.

@DenisCangemi
Created July 22, 2020 13:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DenisCangemi/6bb04ba8f43a38428a7ae9665cf5e5f1 to your computer and use it in GitHub Desktop.
Save DenisCangemi/6bb04ba8f43a38428a7ae9665cf5e5f1 to your computer and use it in GitHub Desktop.
class Product {
constructor(name) {
this.name = name;
}
setName(name) {
this.name = name;
// Return this for chaining
return this;
}
setPrice(price) {
this.price = price;
// Return this for chaining
return this;
}
save() {
console.log(this.name, this.price, this.units);
// Return this for chaining
return this;
}
}
const product = new Product("T-Shirt")
.setName("Jeans")
.setAge(31.99)
.save();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment