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

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

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

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

問(wèn)題描述

<!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ù)調(diào)用?

問(wèn)題解答

回答1:

Number.prototype.toString 標(biāo)準(zhǔn)

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對(duì)象,將會(huì)拋出一TypeError

直接調(diào)用this是window你可以這么用:

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

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

補(bǔ)充一下,答題有點(diǎn)離題了,b()實(shí)際上是作為函數(shù)調(diào)用的,也調(diào)用成功了,錯(cuò)誤是toString()自身拋出來(lái)的。

回答3:

Number.prototype.toString 可以作為函數(shù)調(diào)用但 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

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 免费午夜视频 | 久久黄视频 | 色综合天天综合网国产成人网 | 欧美一级在线观看 | 国产激情小视频 | 中文字幕视频 | 四川一级毛毛片 | 中文在线视频 | 在线观看免费黄色 | 色婷婷在线视频 | 色羞羞 | 免费国产一区二区 | 国产超碰人人模人人爽人人添 | 96精品| www.一区| av片在线看| 青青草免费在线 | 免费的黄色小视频 | 一本不卡 | 欧美日韩在线视频观看 | 国产黄在线观看 | 99视频网 | 天天拍天天射 | 免费的毛片 | 亚洲黄色影院 | 黄色成年 | 69久久久| 欧美综合在线观看 | 91丨九色丨国产在线 | 国产福利视频在线观看 | 日韩欧美在线一区 | 亚洲精品影院 | 97色在线 | 欧美人与野| 美女91网站 | av动漫在线观看 | 成人日韩在线 | 黄色片在线免费观看 | 亚洲精品福利视频 | 亚洲精品播放 | a级片网站|