2

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.

s4san
  • 319
  • 2
  • 9
  • http://blog.slaks.net/2015-06-18/code-snippets-and-in-the-darkness-bind-them/ – SLaks Mar 09 '16 at 15:42
  • 1
    Pointy's answer below is perfectly right. Note that this is still a roundabout way of accessing `call`, so please don't do this in actual code =p – Kyll Mar 09 '16 at 15:42
  • @Kyll Yes, this was just an experiment. I cannot accept the answer yet! :) – s4san Mar 09 '16 at 15:44

1 Answers1

8

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.

Pointy
  • 405,095
  • 59
  • 585
  • 614