Array.prototype.slice web-compat issue?

Andrea Giammarchi andrea.giammarchi at
Tue Sep 10 18:03:47 PDT 2013

Allen if you put the word `Array` but you define it differently then maybe
it's not me misunderstanding ... Float32Array is not an Array in current
ES, that's "fun enough" if you ask me.

In any case, if that was the problem, being an Array, the solution is quite
simple (recycling code, could be better):

(function(Object, ArrayPrototype){
  if (typeof ArrayObject !== 'undefined') return;
  // the only difference
  (ArrayObject = function(){}).prototype = [];
    modify = [
    keys = Object.getOwnPropertyNames(ArrayPrototype),
    create = function(method) {
      return function() {
        return Object.setPrototypeOf(
          method.apply(this, arguments),
    i = keys.length,
    current, key;
  ) {
    key = keys[i];
    current = Object.getOwnPropertyDescriptor(ArrayPrototype, key);
    if (~modify.indexOf(key)) {
      current.value = create(current.value);
    Object.defineProperty(ArrayObject.prototype, keys[i], current);
}(Object, Array.prototype));

and no old code will ever be affected so that in ES6 you can


class Whatever extends ArrayObject {
  // that's it


and if you chose to extend `Array` the slice will produce an `Array`

I think this is a better alternative to potentially broken code ... but I
might be wrong.

Let's wait for this change to break out there, maybe it will not.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list