av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

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

javascript - es6數(shù)值解構Number.prototype.toString is not generic

瀏覽:142日期: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不能作為函數(shù)調用?

問題解答

回答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值不是數(shù)字類型或者Number對象,將會拋出一TypeError

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

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

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

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

回答3:

Number.prototype.toString 可以作為函數(shù)調用但 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
相關文章:
主站蜘蛛池模板: 欧洲一级毛片 | 黄色免费网 | 亚洲欧洲一区二区 | 亚洲国产成人久久综合一区,久久久国产99 | 国产一级片一区二区 | 欧美亚洲综合久久 | 欧美精品一区久久 | 欧美一区二区三区久久精品 | 日韩免费高清视频 | 中文无吗 | 久久69精品久久久久久久电影好 | 麻豆hd| 在线视频一区二区三区 | 国产精品一区免费 | 亚洲一卡二卡 | 毛片网站在线观看 | 亚洲在线成人 | 精品视频在线免费观看 | 午夜影院在线视频 | 在线观看中文字幕av | 久久精品日产第一区二区三区 | www..99re | 一区二区在线看 | 91视频日本| 国产精品视屏 | 日本涩涩网 | 国产精品久久久久久久久久尿 | 亚洲成人网在线 | 精品一区二区久久 | 亚洲精品不卡 | 日韩欧美国产综合 | 精品av| 欧美精品在线播放 | 久久久久久久久综合 | 91av在线电影| 99久久国产综合精品麻豆 | 玖玖国产 | 欧美精品在线播放 | 国产一区二区美女 | 涩涩视频在线观看免费 | 国产人免费人成免费视频 |