Add unsafeHas#14
Conversation
|
@natefaubion could you help me understand what makes this "unsafe"? |
| }; | ||
|
|
||
| exports.unsafeHasFn = function(label, rec) { | ||
| return {}.hasOwnProperty.call(rec, label); |
There was a problem hiding this comment.
How about using Object.prototype.hasOwnProperty.call(rec, label) so that a new object isn't created?
There was a problem hiding this comment.
It's using the same code the compiler generates in record updates. Engines will optimize this out.
|
It's unsafe because it violates referential transparency. The type signature says it works |
|
Maybe referential transparency isn’t the right word? There isn’t a use for this function in safe code since the whole point of records is that you know the fields statically, making this kind of check unnecessary. The only use case for it is if you are making a dynamic assertion about records, which I would consider inherently unsafe. Maybe “disingenuousHas” is a better name? :D |
|
Thanks! |
No description provided.