-2

The title is the question. (Do not mention functions being objects that are callable; it is not the conventional categorization.)

Melab
  • 2,594
  • 7
  • 30
  • 51
  • document.all is an ancient Internet Explorer function returning an htmlcollection, later added to some other browsers like [chrome](https://developer.mozilla.org/en-US/docs/Web/API/Document/all) and deprecated – mplungjan Jun 11 '22 at 19:33
  • [here is an interesting post](https://stackoverflow.com/questions/10350142/why-is-document-all-falsy/62005426) – mplungjan Jun 11 '22 at 19:35
  • "*(Do not mention functions being objects that are callable; it is not the conventional categorization.)*" then what categorisation do you want to use here? – VLAZ Jun 11 '22 at 19:42
  • "*Do not mention functions being objects that are callable*" - why not? Since you already know this, is your actual question whether `document.all` is callable? You should be able to find out by simple trial-and-error. – Bergi Jun 11 '22 at 19:43
  • @VLAZ I prefer the more common-place distinction between `function` and `object` types that does not have one being a superset of the other. – Melab Jun 12 '22 at 19:49
  • @Bergi See [the comment](https://stackoverflow.com/q/72587327/1953537#comment128236019_72587327) I made prior to this one. – Melab Jun 12 '22 at 19:49

1 Answers1

1

.all is a property of the document (or prototype), and that property is a getter that returns a function. In other words, referencing the .all property invokes the getter (which is one function), and then the getter gives you another function. This behavior is specified here (but is way obsolete, and not something you should ever see nowadays).

For example, in Chrome, you can see that the property is a getter in the following:

console.log(
  Object.getOwnPropertyDescriptor(Document.prototype, 'all')
);

and that the value returned is callable by calling it:

document.all();

The value returned by the getter is an HTMLAllCollection.

It doesn't inherit from Function.prototype, so it's not a normal function - it's an exotic object - but it does have a [[Call]] internal method and so is callable and can be called a function. (and functions are also objects, of course, as you know)

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
  • "*you can see this in the following*" - I can only see that the `.all` getter is a function, not that the `HTMLAllCollection` it will return is callable – Bergi Jun 11 '22 at 19:48
  • So, would a good correction of `typeof value` be to return `"function"` if `typeof value === "undefined"` and `value !== undefined`? – Melab Jun 12 '22 at 20:04
  • @Melab Yes, it would return `"function"` if it wasn't special-cased [for reasons](https://stackoverflow.com/q/10350142/1048572). – Bergi Jun 12 '22 at 20:08