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

%TypedArray%.of does not use @@species #1157

Closed
TimothyGu opened this issue Mar 29, 2018 · 1 comment
Closed

%TypedArray%.of does not use @@species #1157

TimothyGu opened this issue Mar 29, 2018 · 1 comment
Labels

Comments

@TimothyGu
Copy link
Member

%TypedArray%.of uses the this value as the constructor, not this[Symbol.species]. This seems inconsistent with the methods on %TypedArrayPrototype% like subarray and slice.

@allenwb
Copy link
Member

allenwb commented Mar 29, 2018

No, it's correct as written and handled exactly the same as in %Array%.of

of is a factory method of the constructor so the actual class constructor to be instantiated is the thisValue passed to the factory. What the algorithm is doing is approximately this:

class %TypedArray% {
   of(...args) {
      let ta = new this(args.length
      for (let i=0; ++1; i<args.length) ta[i]=args[i];
      return ta;
  }
}

When used in an expression referencing a subclass such as Int32Array.of(1,2,3) the value of this within the inherited method will be %Int32Array%. Essentially the expression is explicitly naming the kind of typed array it wants to instantiate.

@@species is primarily for use in instance methods that create derived collections whose class isn't explicit stated at the usage site.

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

3 participants