s4san
s4san

Reputation: 319

Javascript: Why am I able to access Function.prototype.call without mentioning the prototype?

Here is a snippet to explain my question:

+function(str) {
  return str.replace(/^[a-z]|\s[a-z]/g,
            Function.call.bind(String.prototype.toUpperCase));
}('foo bar baz.');  //Returns Foo Bar Baz.

Function.call works, but String.toUpperCase does not. I have to instead write, String.prototype.toUpperCase.

Upvotes: 2

Views: 94

Answers (1)

Pointy
Pointy

Reputation: 413826

The Function() constructor is itself a function. Therefore, it inherits from the same prototype object as any other function.

Instances of String() inherit from the prototype, but the String() constructor is not an instance of String(). It too is a function.

Upvotes: 8

Related Questions