Is it possible to model Object.getOwnPropertyNames in IE8

Can I model Object.getOwnPropertyNames in IE8?

I am trying to get this fiddle to work in IE8.

I believe that it remains only to make a function simulating getOwnPropertyNames .

Of course, much attention is paid to other solutions to the basic task of extending a JavaScript object with object literals in IE8.

Updated : A fiddle that uses the external esm shm script file is running.

Conclution : No, but you can pin Object.keys

+4
source share
1 answer

No.

Object.getOwnPropertyNames() returns both enumerated and non-enumerated native properties of an object. It is not possible to iterate over non-enumerable properties in ECMAScript 3rd Edition implementations, so you can only get those that are listed.

It’s quite simple to write a procedure to return enumerated own properties:

 var arr = []; for (var k in obj) { if (obj.hasOwnProperty(k)) arr.push(k); } 

This is (more or less) the equivalent of Object.keys() . If this is not enough, then you are out of luck.

+8
source

Source: https://habr.com/ru/post/1382677/


All Articles