色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術文章
文章詳情頁

javascript - es6數值解構Number.prototype.toString is not generic

瀏覽:144日期:2023-04-27 14:18:21

問題描述

<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Document</title></head><body> <script>({toString:b} = 123);console.log(b === Number.prototype.toString); // trueconsole.log(Number.prototype.toString()); // 0console.log(b()); // Number.prototype.toString is not genericlet num = 456;console.log(num.b()); // num.b is not a function </script></body></html>

為什么b不能作為函數調用?

問題解答

回答1:

Number.prototype.toString 標準

The toString function is not generic; it throws a TypeError exception if its this value is not a Number or a Number object. Therefore, it cannot be transferred to other kinds of objects for use as a method.

翻譯一下后面的:

如果他的this值不是數字類型或者Number對象,將會拋出一TypeError

直接調用this是window你可以這么用:

b.call(1)b.call(Number(’test’))回答2:

你可以b.call(num),一般來說toString不允許作為普通函數執行很容易接受,就跟構造函數一般不作為普通函數執行一樣。ps:例子中的Number.prototype.toString()實際上作用域也是Number.prototype

補充一下,答題有點離題了,b()實際上是作為函數調用的,也調用成功了,錯誤是toString()自身拋出來的。

回答3:

Number.prototype.toString 可以作為函數調用但 this 一定要是 Number 類型。其他類型的 toString 同理。

b.call(123)// '123'

The toString function is not generic; it throws a TypeError exception if its this value is not a Number or a Number object. Therefore, it cannot be transferred to other kinds of objects for use as a method.

15.7.4.2 Number.prototype.toString

標簽: JavaScript
相關文章:
主站蜘蛛池模板: 中文字幕在线永久 | 国产成人91高清精品免费 | 99精品这里只有精品高清视频 | 国产一级一级一级国产片 | 亚洲性久久 | 18女人毛片大全 | 一级国产在线观看高清 | 亚洲精品第一国产综合野 | 国产最猛性xxxxxx69交 | 国产黄网| 亚洲精品线在线观看 | 免费日韩在线视频 | 国产亚洲欧洲精品 | 99在线小视频 | 中文字幕亚洲精品第一区 | 综合精品视频 | 国产精自产拍久久久久久 | 久久99热成人精品国产 | 久久国产精品免费视频 | 亚洲的天堂 | 99热.com| 欧美aaaaa一级毛片在线 | 91精品国产高清久久久久久io | 精品日韩欧美一区二区三区在线播放 | 成人免费高清视频 | jizjiz日本 | 国产网站黄 | 日韩午夜 | 午夜在线亚洲男人午在线 | 成人自拍网 | 美女福利视频午夜在线 | 久久精品久久久久 | 欧美上床视频 | 玖玖在线免费视频 | 午夜影院0606| 国产三级黄色片 | 国产精品久久国产精品99盘 | 中文字幕视频网站 | 国产精品久久久久三级 | 免费一级特黄特色黄大任片 | 亚洲天堂视频网 |