r/javascript • • Aug 27 '16

Is your JavaScript function actually pure?

http://staltz.com/is-your-javascript-function-actually-pure.html
8 Upvotes

48 comments sorted by

View all comments

0

u/[deleted] Aug 27 '16

[deleted]

-3

u/DanielRosenwasser TypeScript Aug 27 '16

I'm not sure if you read through the whole thing, but that's sort of the point of the article. There's crazy stuff you can do in JS, but for the most part there are ways that are good enough to run with certain assumptions. Otherwise you'll vex over these ridiculous corner cases and never get anything done.

0

u/[deleted] Aug 27 '16

[deleted]

1

u/vinnl Aug 28 '16

I think the main point is not that you should or could breach the contract, but rather to make you aware of the implicit parts of the contract, and how you can make some parts of it explicit as desired. For example, passing undefined or null when an actual value is expected is a breach of contract that does happen in practice, so you might want to defend against that.

1

u/neophilus77 Aug 29 '16

You shouldn't have to defend against bad data, bad data is a symptom of a bug somewhere else

1

u/vinnl Aug 30 '16

Yes, and that bug will surface if the data is rejected as soon as possible.