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

Conversation

ya7ya
Copy link
Contributor

@ya7ya ya7ya commented Mar 8, 2018

trying to fix ipfs/js-ipfs#1131 properly.
cc @diasdavid

Signed-off-by: Yahya [email protected]

@vmx vmx merged commit e386738 into multiformats:master Mar 8, 2018
@vmx
Copy link
Member

vmx commented Mar 8, 2018

Thanks a lot @ya7ya. I just changed the commit message to match the JS Code Guidelines.

@@ -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.

@@ -415,7 +415,7 @@ Multiaddr.protocols = protocols
*/
Multiaddr.isMultiaddr = function isMultiaddr (addr) {
if (addr.constructor && addr.constructor.name) {
return addr.constructor.name === 'Multiaddr'
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.

@vmx
Copy link
Member

vmx commented Mar 9, 2018

@diasdavid Sorry I thought the revert was already merged, but it was only approved.

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 this pull request may close these issues.

Uncaught Error: Can't set property: 'links' is immutable
4 participants