Skip to content
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

breaks on a date #24

Closed
matthewmueller opened this issue Mar 18, 2015 · 1 comment · Fixed by #31
Closed

breaks on a date #24

matthewmueller opened this issue Mar 18, 2015 · 1 comment · Fixed by #31
Assignees

Comments

@matthewmueller
Copy link

Example:

var Immutable = require('seamless-immutable');
var d = { date: new Date() };
console.log(d.date.toISOString());
var d = Immutable(d);
console.log(d.date.toISOString());

Console:

2015-03-18T03:17:29.895Z
/Users/matt/Playground/seamless-immutable/index.js:5
console.log(d.date.toISOString());
                   ^
TypeError: undefined is not a function
    at Object.<anonymous> (/Users/matt/Playground/seamless-immutable/index.js:5:20)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3
@matthewmueller matthewmueller changed the title breaks on a Date breaks on a date Mar 18, 2015
@rtfeldman rtfeldman self-assigned this Mar 18, 2015
@rtfeldman
Copy link
Owner

This is because currently seamless-immutable does not copy over prototypes, and as such always returns a vanilla Object.

Copying over prototypes is a bit of a double-edged sword. Something like .toISOString() should work as normal on an immutable object, so there's not much downside there. However, other methods might attempt to mutate the object and then fail silently (depending on whether Strict Mode is enabled). There's an element of "buyer beware" to copying prototypes.

That said, I suppose there's not much difference between deciding to use a prototype with mutating methods and just attempting to mutate an immutable object yourself, so on balance this seems like a reasonable change to make. At the very least, it ought to address the proximal issue of Date.toISOString becoming unavailable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants