-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Typed Arrays #90
Comments
Ah wait, it does actually make a copy. They say "shallow" copy, but typed arrays are of primitive types anyway so I don't really understand this distinction. Possibly for future types which can host references to more structured things. So, a polyfill should be easy then, basically a for loop copying elements into a new typed array of the same type and returning it. EDIT: found a polyfill at https://github.com/inexorabletash/polyfill/blob/master/typedarray.js#L795 though this emulates all of typedarrays I think |
Currently, I'm thinking about adding only missing methods or, possible, adding complete polyfill, but not in near versions. |
Given the fast advances of browsers I wouldn't waste time adding full typed arrays polyfills, but rather only add the missing functions of the latest browser versions. Like the slice method in my case. I see core-js more as a tool to be able to use the future now, not as something to support old browsers, but of course, there is some overlap. |
For reference, this is my working polyfill, adapted from https://github.com/inexorabletash/polyfill/blob/master/typedarray.js: "use strict"
for (let TA of [Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array]) {
if (!TA.prototype.slice) {
TA.prototype.slice = function (start, end) {
var len = this.length
var relativeStart = start
var k = (relativeStart < 0) ? max(len + relativeStart, 0) : Math.min(relativeStart, len)
var relativeEnd = (end === undefined) ? len : end
var final = (relativeEnd < 0) ? max(len + relativeEnd, 0) : Math.min(relativeEnd, len)
var count = final - k
var c = this.constructor
var a = new c(count)
var n = 0
while (k < final) {
var kValue = this[k]
a[n] = kValue
++k
++n
}
return a
}
}
} Note that I couldn't use |
Available in 2.0. |
👍 |
I wanted to use the slice function of TypedArray and saw there is no polyfill. I also couldn't find one somewhere else with a quick search. Is it possible to implement that? I'm not sure as it seems to be quite native and hard to emulate without actually making a copy of the array. But maybe (hopefully) I'm wrong.
The text was updated successfully, but these errors were encountered: