3

In this question it is recommended in order get all native objects to use the global object. However the answer is incomplete as there are other native objects which are not accessible through the global object.

I know of at least one-- Arguments which has no reference from the global object. What other constructors are not accessible through the global object?

This question is not limited to browsers, but could include Node as well.

Community
  • 1
  • 1
Eli
  • 431
  • 4
  • 11
  • What is the one that you know of? – epascarello Oct 25 '12 at 04:05
  • I stated it in my question -- `Arguments` (that is the Arguments constructor). Let me format it a little better so that is more obvious – Eli Oct 25 '12 at 04:08
  • 1
    Related http://stackoverflow.com/questions/2257993/how-to-display-all-methods-in-a-javascript-object – epascarello Oct 25 '12 at 04:20
  • I never heard about an `Arguments` constructor. Isn't `arguments` an instance of `Object`? – bfavaretto Oct 25 '12 at 04:45
  • `Arguments` is in fact a native type. You can test it with the following: var args = (function () {return arguments})(); console.log(Object.prototype.toString.call(args)); You will have `[object Arguments]` printed to the console. – Eli Oct 25 '12 at 13:45
  • 1
    @Eli ALthough your code does output what you say, it doesn't mean there's an `Arguments` constructor. See [section 10.6 of the language specification](http://es5.github.com/#x10.6). So I don't know what would be a valid answer to your question. Maybe "native objects are all accessible through the global object, and may be inspected with [`Object.getOwnPropertyNames`](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/getOwnPropertyNames)". – bfavaretto Oct 25 '12 at 15:42
  • +1. @bfavaretto You are correct. Not being familiar with the language specification I assumed if an object had a unique class (as represented in Object.prototype.toString.call) it was a native type. Looks like I need to get more familiar with the language spec. If anyone else would like proof of what @bfavaretto has said, try the following: `var args = (function () { return arguments; })(); console.log(Object.getPrototypeOf(args) === Object.getPrototypeOf({})); console.log(args.constructor === ({}).constructor);` – Eli Oct 25 '12 at 16:01
  • @bfavaretto If you put your comment in the form of an answer I will select it as the correct answer. – Eli Oct 25 '12 at 16:11

1 Answers1

1

When you list all objects referenced on the global object, that will include native objects (core language objects) and host objects (supplied by the host environment; in a browser, all the DOM stuff, and more). That's all we can use on our code.

There is no Arguments constructor on that list. There could be one, but there isn't:

The arguments object is created by calling the abstract operation CreateArgumentsObject ECMAScript 5.1, Section 10.6

Roughly, that operation creates a regular Object (standard constructor, standard prototype), extends it with some extra properties like length, and sets its [[Class]] internal property to "Arguments". That's why arguments.toString() is [object Arguments].

bfavaretto
  • 71,580
  • 16
  • 111
  • 150