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

core-js-pure/features/set with custom objects #575

Closed
jml6m opened this issue Jun 17, 2019 · 5 comments
Closed

core-js-pure/features/set with custom objects #575

jml6m opened this issue Jun 17, 2019 · 5 comments
Labels

Comments

@jml6m
Copy link

jml6m commented Jun 17, 2019

Seeing some errors. I have class Foo as such:

export class Foo {
  name;

  constructor(name) {
    this.name = name;
  }
}

I'd like to use the Set.isSubsetOf() method but neither core-js-pure/features/set or core-js/features/set gives me fully what I want:

import Set from "core-js-pure/features/set";
import { Foo } from "./Foo.js";

let q1, q2, q3, test, test2;
q1 = new Foo("q1");
q2 = new Foo("q2");
q3 = new Foo("q3");

test= new Set([q1, q2]);
test2= new Set([q1, q2, q3]);

console.log(test); // prints Set {}
console.log(test2); // prints Set {}
console.log(Set.isSubsetOf(test,test2)); // prints true

The method works, but my Sets aren't being populated. If I use core-js/features/set on the same code, here is what the console prints:

console.log(test); // prints Set { Foo { name: 'q1' }, Foo { name: 'q2' } }
console.log(test2); // prints Set { Foo { name: 'q1' }, Foo { name: 'q2' }, Foo { name: 'q3' } }
console.log(Set.isSubsetOf(test,test2)); // throws TypeError: _set.default.isSubsetOf is not a function

I'm pretty sure core-js-pure/features/set is the correct import but something is going on with the constructor.

@zloirock
Copy link
Owner

zloirock commented Jun 17, 2019

isSubsetOf is a Set prototype method. You should use

test.isSubsetOf(test2)

@jml6m
Copy link
Author

jml6m commented Jun 17, 2019

@zloirock Thank you for clarifying here, that did work. However, the other issue I pointed out, you didn't address. Why aren't Sets with custom objects being populated when using core-js-pure/features/set?

@zloirock
Copy link
Owner

@jml6m I can't understand what do you mean.

@jml6m
Copy link
Author

jml6m commented Jun 17, 2019

In my post, you'll see the code I create a new Set([q1, q2]); but console.log prints an empty object. The Set is not being created properly.

@zloirock
Copy link
Owner

zloirock commented Jun 17, 2019

If you don't see it in your console, it does not mean that it's not created. It's just problems of your console. Try, for example, new Set([q1, q2]).has(q1) or [...new Set([q1, q2])].

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

No branches or pull requests

2 participants