Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up%TypedArray%.of does not use @@species #1157
Comments
TimothyGu
referenced this issue
Mar 29, 2018
Closed
buffer: do not emit deprecation notice on Buffer.of #19682
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
allenwb
Mar 29, 2018
Member
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.
|
No, it's correct as written and handled exactly the same as in %Array%.of
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 @@species is primarily for use in instance methods that create derived collections whose class isn't explicit stated at the usage site. |
TimothyGu commentedMar 29, 2018
%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.