Created
July 22, 2020 13:33
-
-
Save DenisCangemi/6bb04ba8f43a38428a7ae9665cf5e5f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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