午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

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

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

瀏覽:242日期: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
相關文章:
主站蜘蛛池模板: 欧美日韩在线观看免费 | 夜夜夜久久久 | 第一福利丝瓜av导航 | 久久精品无码一区二区三区 | 五月香蕉网 | 欧美一级大片在线观看 | 老司机黄色片 | 午夜视频黄 | 超碰97在线播放 | 国产精品久久不卡 | 日韩欧美卡一卡二 | 日韩亚洲国产欧美 | 久久99国产综合精品免费 | 波多野结衣一二区 | 亚洲一区欧美二区 | 亚洲香蕉中文网 | 久艹视频在线 | 你懂的成人 | 午夜一级视频 | 日本五十路视频 | 美国黄色大片 | 亚洲精品卡一卡二 | 亚洲狠狠干 | 五十路一区| 女人天堂av | 成年人免费网站在线观看 | 成人深夜视频 | 另类色综合 | 亚洲男女啪啪 | 可以在线观看av的网站 | 林心如三级全黄裸体 | 91亚洲国产 | 亚洲片在线观看 | 国产成人综合在线 | 一级欧美一级日韩片 | 在线a网 | 亚洲日日夜夜 | 在线观看国产成人 | xxx一区| 台湾佬中文字幕 | 女人毛片视频 |