亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

瀏覽:130日期: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
相關文章:
主站蜘蛛池模板: 成人在线视屏 | 国产精品视频无圣光一区 | 国产片一级毛片视频 | 国产精品成 | 欧美精品一区在线看 | 免费a一级毛片在线播放 | 国产高清好大好夹受不了了 | 亚洲欧美日韩国产精品网 | 色婷婷综合欧美成人 | 看全色黄大色黄大片色黄看的 | 国精产品一区一区三区 | 久久视频在线看 | 视频二区 调教中字 知名国产 | 欧美毛片网站 | 性视频一级 | 日韩爆操 | 亚洲欧美日韩一区二区在线观看 | 成年男女男免费视频网站不卡 | 国产 日韩 欧美视频二区 | 俺去鲁婷婷六月色综合 | 国产区成人综合色在线 | 最新国产精品自拍 | 免费中文字幕在线 | 日韩高清在线不卡 | 欧美剧场成人精品午夜 | 成人综合视频网 | 国产一区二区三区播放 | 99久久免费国产特黄 | 国产中文99视频在线观看 | 绝对真实偷拍盗摄高清在线视频 | 亚洲一级黄色片 | 欧美成人精品不卡视频在线观看 | 国产高清在线精品一区αpp | 亚洲精品综合一区二区 | 国内精品伊人久久久影视 | 一区二区视频在线播放 | 国产91精品久久久久久 | 俄国特级毛片www免 俄罗斯14一18处交 | 亚洲免费一区二区 | 真实国产乱子伦对白视频37p | 黄色一级在线 |