簡體   English   中英

Javascript:為什么我能在不提及原型的情況下訪問Function.prototype.call?

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

這是一個解釋我的問題的片段:

+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有效,但String.toUpperCase不起作用。 我必須改為編寫String.prototype.toUpperCase

Function()構造函數本身就是一個函數。 因此,它從與任何其他函數相同的原型對象繼承。

String()實例繼承自原型,但String()構造函數不是 String()的實例。 它也是一種功能。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM