Last active
January 18, 2019 02:32
-
-
Save rxluz/76a3ffea82eff3f7fdee39c25f18e2f8 to your computer and use it in GitHub Desktop.
S.O.L.I.D Principles for JS with examples, see more at https://medium.com/p/db95b44e82e
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 { | |
setName({ name, onFinish }) { | |
this.name = name; | |
onFinish(this); | |
} | |
} | |
const run = () => { | |
const ProductInstance = new Product(); | |
ProductInstance.setName({ | |
name: "Pen", | |
onFinish() { | |
console.log("Added succefully"); | |
}, | |
}); | |
ProductInstance.setName({ | |
name: "Pencil", | |
onFinish() {}, | |
}); | |
// this is generate a error: | |
ProductInstance.setName({ | |
name: "Other pencil", | |
}); | |
//returns TypeError: onFinish is not a function | |
}; | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment