-2

Im using vue/vuetify, and i'm trying to get it to work in IE11. When I run it, I get this error

TypeError: Object doesn't support property or method 'values'

but then when I add a pollyfill

    if (!Object.values) {
        Object.prototype.values = function (obj) {
            return Object.keys(obj).map(function (e) {
                return obj[e];
            });
        };
    }

I get this from jquery 3.4.0

Object.keys: argument is not an Object

because it ends up calling the above function, but not passing any params to it. From here

    add = function( key, valueOrFunction ) {

        // If value is a function, invoke it and use its return value
        var value = isFunction( valueOrFunction ) ?
            valueOrFunction() :
            valueOrFunction;

        s[ s.length ] = encodeURIComponent( key ) + "=" +
            encodeURIComponent( value == null ? "" : value );
    };

it calls

valueOrFunction() // which is the Object.values()

Here is a jsfiddle

https://jsfiddle.net/cn75e4xs/3/

Open in IE11, and see console tab. I get

Object.keys: argument is not an Object

because the function gets called without passing a parameter, so obj becomes undefined in the pollyfill.

enter image description here

omega
  • 40,311
  • 81
  • 251
  • 474
  • 1
    Possible duplicate of [Alternative version for Object.values()](https://stackoverflow.com/questions/42830257/alternative-version-for-object-values) – Jonathan Gagne Apr 22 '19 at 19:01
  • Note that while the duplicate's accepted answer uses code similar to yours, there are a number of answers that don't; you should try those. – Heretic Monkey Apr 22 '19 at 19:02
  • I added a jsfiddle. I used the code from the accepted answer, but the problem is jquery is calling it but without passing any params. – omega Apr 22 '19 at 19:04
  • From [jQuery's Browser Support page](https://jquery.com/browser-support/) (which includes IE9+): "Any problem with jQuery in the above browsers should be reported as a bug in jQuery." – Heretic Monkey Apr 22 '19 at 19:07
  • Is the browser running in IE8 mode or something? – epascarello Apr 22 '19 at 19:11
  • At this point... i'm not confident that this is a jquery problem at all. It appears as though jquery's source does not call Object.values at all. – Kevin B Apr 22 '19 at 19:12
  • Its on IE11. The jsfiddle replicates the issue, if you can run in IE11, and look at console. – omega Apr 22 '19 at 19:13
  • If you put a breakpoint on my pollyfill, you will see it gets called, and there is no parameter. – omega Apr 22 '19 at 19:13
  • The fiddle doesn't function at all for me, the two html files 404, and that's it. – Kevin B Apr 22 '19 at 19:14
  • I put a picture on top. It shows that my pollyfill function gets called, and on the right side, it shows it gets called from jquery. – omega Apr 22 '19 at 19:16
  • The fiddle will work, after you click the open in readonly mode, and then page will be white, but you just need to check in console tab. Keep it open before opening the fiddle. – omega Apr 22 '19 at 19:17
  • You are assigning to `Object.prototype.values` for some reason. You should be assigning to `Object.values` instead. Where did you find that polyfill? – Bergi Apr 22 '19 at 19:20

1 Answers1

1

You are assigning to Object.prototype.values for some reason. You should be assigning to Object.values instead:

Object.values = function (obj) {
//    ^ no .prototype
    return Object.keys(obj).map(function (e) {
        return obj[e];
    });
};

The jQuery code broke because you added a property to Object.prototype without making it non-enumerable.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375