延長字符串原型下面是代碼我不能在JavaScript
<script>
String.prototype.testthing = function() {
return "working";
}
alert(String.testthing());
</script>
當我打開這個網頁,我得到以下
Uncaught TypeError: Object function String() { [native code] } has no method 'testthing'
錯誤我想不出爲什麼。我已經擴展了Array原型而沒有問題。
好了,'字符串!== String.prototype'原型。 –
更重要的是(IMO),'Object.getPrototypeOf(String)!== String.prototype'。 – ephemient