Object.getPrototypeOf(arguments) VS [[Class]]

# Andrea Giammarchi (13 years ago)

I just wonder if anyone can explain why functions arguments [[Class]] is Arguments but Object.getPrototypeOf(arguments) is Object.prototype

This looks to me inconsistent against every other [[Class]] different from Object case:either the class Arguments exists, or it doesn't, don't you think?

!function(){ Object.getPrototypeOf(arguments) == Object.prototype; // true {}.toString.call( Object.getPrototypeOf(arguments) ) == {}.toString(); // true again }();

Thanks for clarifications.

# Brendan Eich (13 years ago)

ES1-3 had arguments pretending to be "Object" but not actually an Object instance.

ES5 changed to use an internal class with name "Arguments". No Arguments constructor, Arguments.prototype, etc.

I don't think we should polish the arguments turd further.

# Andrea Giammarchi (13 years ago)

So the check to know if an object is Arguments cross version would be like this, correct?

function isArguments(object) { return -1 < {}.toString.call(object).indexOf(" Arguments]") || ( typeof object == "object" && !(object instanceof Object) ); }

alert([ isArguments({}), isArguments(function(){return arguments}()) ]);

# Andrea Giammarchi (13 years ago)

null ...

function isArguments(object) { return -1 < {}.toString.call(object).indexOf(" Arguments]") || ( !!object && typeof object == "object" && !(object instanceof Object) ); }

# Brendan Eich (13 years ago)

Andrea Giammarchi wrote:

null ...

function isArguments(object) { return -1 < {}.toString.call(object).indexOf(" Arguments]") || ( !!object && typeof object == "object" && !(object instanceof Object)

Sorry, this isn't right. When I wrote "ES1-3 had arguments pretending to be "Object" but not actually an Object instance" I did not mean !(argsobj instanceof Object). I meant literally that arguments instances are of an internal class. Kind of like proxies, because they alias function formal parameters.

In ES1-3 it's hard to detect an arguments object. Something like

object instanceof Object && !object.propertyIsEnumerable('length')

(where propertyIsEnumerable includes hasOwnProperty)?

# Andrea Giammarchi (13 years ago)

object instanceof Object && !object.propertyIsEnumerable('**length')

every Array will be ... uhm, I remember the trick then was about looping through for/in ... problem is, if length is 0 there's no way to udnerstand if that object is arguments or not.

Right

# Andrea Giammarchi (13 years ago)

gist.github.com/4163041

that should be it.