[英]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. Function.call
有效,但String.toUpperCase
不起作用。 I have to instead write, String.prototype.toUpperCase
. 我必须改为编写String.prototype.toUpperCase
。
The Function()
constructor is itself a function. 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()
. String()
实例继承自原型,但String()
构造函数不是 String()
的实例。 It too is a function. 它也是一种功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.