4 ms·
I am sure before you started this project you looked at other existing libraries. How is this solution compared with the lodash _.cloneDeep https://lodash.com/d
by fiallega 8y ago
I am sure before you started this project you looked at other existing libraries. How is this solution compared with the lodash _.cloneDeep https://lodash.com/docs/4.17.11#cloneDeep https://lodash.com/docs/4.17.11#cloneDeep.
Thanks
- jfet97 8y agoNo I've built it on my own. I only know that popular libraries as lodash don't call constructors, so I think there is no way to mantain a proper [[Prototype]] nor the constructor props. IDK how other libraries do to handle circ references nor if them allow to copy non-enums props and getters&setters.
- porphyrogene 8y agoYou don’t need to use the constructor syntax to have an object inherit prototypes from another.
- erikpukinskis 8y agoHow do you do it without a constructor? Iterate over the properties on the prototype?
- porphyrogene 8y agoThe global Object’s assign method is the “old” way to inherit prototypes. ES6 syntax did not add new language features; they were there all along.
- fiallega 8y agoThanks a lot for all clarifications.
- porphyrogene 8y agoNo problem. A good exercise I used to do was writing inheritence patterns first with pre-ES6 syntax, then constructors, then classes. They are, of course, interchangeable but it’s not wise to rehearse an anti-pattern. EDIT: I said assign method earlier, I meant create. The assign method is the pre-ES6 way of creating object instances. Object.create() is used to inherit prototypes. That’s such a common mix-up that I’m embarrassed I didn’t catch it.
- erikpukinskis 8y agoI just don’t use ES6. It’s amazing. I have such a smaller language surface, and so much more predictable and debuggable code. Not a popular approach though. (Of course I can and do use ES6 when coding for other people, I write to whatever standard is established in a codebase.)