-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve object prototypes #25
Comments
I'm no expert at this but as far as I can tell something like this could work: In the Instead the following can be done: But that won't work for
But
A bit slower in Chrome but still much slower in Firefox (but mainly since FF is much faster at doing But I don't know how much the performance of this single thing affects the entire process of making an object immutable. So am I on the right track? And is there a faster/better way of checking for a prototype? |
Upon further investigation, there are pitfalls to the prototype-only approach. For example, In light of that, I'm leaning toward this not being a good idea after all. It seems like it could lead to surprising bugs, where you can call most methods on most prototypes and have everything work as expected, but good luck tracking down the first bug that comes up because a prototype method relied on a non-enumerable hidden member... |
Yes, that sounds reasonable. But instead of a generic solution for prototypes maybe a special case for |
That seems totally reasonable, yeah. We already do an |
Resolved by #31 |
Hi all, I understand the need to keep things as tight as possible but this is a big issue when you're trying to use custom types that use the prototype. For instance, I'm building a However, the way I see it, whatever happens within the Even though I can assign these myself when creating my I understand the goals of What are your thoughts on this? |
The core issue with prototypes is #25 (comment) - specifically, that there's no way to detect whether prototypes are relying on hidden properties, which cannot be discovered and cloned. The resulting bugs could have really nasty symptoms to identify; things as vague as "the cloned version doesn't quite work the same way as the original for some reason." I could see offering a workaround similar to custom mergers, where you could pass a custom cloning function as an argument to Then if you wanted that prototype behavior everywhere you could just set Thoughts? |
@rtfeldman I'm sorry I haven't come back to you on this before. |
Cool. This is admittedly not a high priority for me in terms of implementation, but I'm on board with the approach! 😃 |
Good stuff! Don't worry, I'll see if I can give it a go at some stage. As a On Wed, 24 Jun 2015 22:58 Richard Feldman notifications@github.com wrote:
|
Currently, if you pass an object with a prototype to
Immutable
, that prototype is discarded. It seems reasonable to preserve that prototype instead, with the understanding that not all of the methods it exposes will necessarily still work.This would address #24
The text was updated successfully, but these errors were encountered: