1 min readMar 15, 2018
Interest concept, going to consider if this is something I want to use in future work.
One suggestion to simplify your final example, instead of:
function makeShoppingCart({
addProduct,
empty,
getProducts,
removeProduct,
...others
}) { return Object.freeze({
addProduct,
empty,
getProducts,
removeProduct,
someOtherMethod,
...others
)} function someOtherMethod () {
// code
}
}
You could simply do:
function makeShoppingCart(productList) { return Object.freeze({
someOtherMethod,
...productList
)} function someOtherMethod () {
// code
}
}
Since all fields are just past directly into Object.freeze()
.
Cheers!