You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"use strict";console.log("%s\n%s\n%s\n%s\n%s\n%s",typeof[]==="object",// supposed to be true[]instanceofObject,// supposed to be true[]instanceofArray,// supposed to be trueArray.isArray([]),// supposed to be trueSymbol.iteratorin[],// supposed to be a trueObject.getPrototypeOf([])===Array.prototype// supposed to be true);
How often does it reproduce? Is there a required condition?
100% reproduction rate, it always has the same results.
What is the expected behavior?
It is expected that object literals share their prototype with Object, and that array literals share their prototype with Array, thus an instanceof check against Object or Array respectively should show true, and this is true for all browsers, Deno, is documented at MDN, yet I couldn't find what the ECMAScript spec had to say about this.
Interestingly, the Node terminal repl showed the expected results, while running a file didn't.
This was run in strict mode and in sloppy mode, without a difference in output.
What do you see instead?
Array literals do not share the prototype of the global Array class.
Additional information
This may not be standard compliant, and shouldn't break any legacy code, as it would be odd to check that an array is an array through an instanceof check instead of Array.isArray.
The text was updated successfully, but these errors were encountered:
$ cat x.js
"use strict";
console.log(
"%s\n%s\n%s\n%s\n%s\n%s",
typeof [], // supposed to be true
[] instanceof Object, // supposed to be true
[] instanceof Array, // supposed to be true
Array.isArray([]), // supposed to be true
Symbol.iterator in [], // supposed to be a true
Object.getPrototypeOf([]) === Array.prototype // supposed to be true
);
$ node -v
v12.18.2
$ node x.js
object
true
true
true
true
true
Anything else about your environment that may be relevant here? Are you setting NODE_OPTIONS in any way, or setting any other relevant environment variables/command line flags?
$ cat x.js
"use strict";
console.log(
"%s\n%s\n%s\n%s\n%s\n%s",
typeof [], // supposed to be true
[] instanceof Object, // supposed to be true
[] instanceof Array, // supposed to be true
Array.isArray([]), // supposed to be true
Symbol.iterator in [], // supposed to be a true
Object.getPrototypeOf([]) === Array.prototype // supposed to be true
);
$ node -v
v12.18.2
$ node x.js
object
true
true
true
true
true
Anything else about your environment that may be relevant here? Are you setting NODE_OPTIONS in any way, or setting any other relevant environment variables/command line flags?
Interesting, it turns out that my environment was setup incorrectly, I'll close this and report it to those who setup the environment instead.
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
100% reproduction rate, it always has the same results.
What is the expected behavior?
It is expected that object literals share their prototype with
Object
, and that array literals share their prototype withArray
, thus aninstanceof
check againstObject
orArray
respectively should showtrue
, and this is true for all browsers, Deno, is documented at MDN, yet I couldn't find what the ECMAScript spec had to say about this.Interestingly, the Node terminal repl showed the expected results, while running a file didn't.
This was run in strict mode and in sloppy mode, without a difference in output.
What do you see instead?
Array literals do not share the prototype of the global
Array
class.Additional information
This may not be standard compliant, and shouldn't break any legacy code, as it would be odd to check that an array is an array through an
instanceof
check instead ofArray.isArray
.The text was updated successfully, but these errors were encountered: