Skip to content

avoid constructor.name pattern #55

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

Merged
merged 1 commit into from
Mar 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ Multiaddr.protocols = protocols
*/
Multiaddr.isMultiaddr = function isMultiaddr (addr) {
if (addr.constructor && addr.constructor.name) {
return addr.constructor.name === 'Multiaddr'
Copy link
Member

@daviddias daviddias Mar 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, this will fail terribly when we have multiple versions of Multiaddr flying around. Which happens often given the myriad of modules we have that import Multiaddr and also the user apps.

return (addr instanceof Multiaddr)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vmx @dryajov I see that you haven't released yet, good. Can you revert this please?

We never use instanceof anywhere for module classes because it breaks when two versions are being used and func A passes the wrong version to func B and then the check fails.

}

return Boolean(
Expand Down