Is it preferable to use closures instead of instance properties? What is the memory overhead in keeping parent scopes alive, compared to passing properties down as instance properties?
const FooFactory = ({ id }) => {
const proto = {
getIdFromClosure() {
return id;
},
getId() {
return this.id;
}
};
return Object.create(proto, { id: { value: id } });
};
const foo = FooFactory({ id: 123 });
foo.getIdFromClosure(); // 123
foo.getId(); // 123