为了账号安全,请及时绑定邮箱和手机立即绑定

请问下 ecma 里 ToPrimitive([]) 怎么把hint 转成 string 的

请问下 ecma 里 ToPrimitive([]) 怎么把hint 转成 string 的

沧海一幻觉 2019-03-22 22:19:05
为了解决这个问题: [] + [] === "", 请问下 ToPrimitive([]) 怎么把hint 转成 string 的ToPrimitive ( input [ , PreferredType ] )The abstract operation ToPrimitive takes an input argument and an optional argument PreferredType. The abstract operation ToPrimitive converts its input argument to a non-Object type. If an object is capable of converting to more than one primitive type, it may use the optional hint PreferredType to favour that type. Conversion occurs according to the following algorithm:Assert: input is an ECMAScript language value.If Type(input) is Object, thenLet result be ? Call(exoticToPrim, input, « hint »).If Type(result) is not Object, return result.Throw a TypeError exception.If PreferredType is not present, let hint be "default".Else if PreferredType is hint String, let hint be "string".Else PreferredType is hint Number, let hint be "number".Let exoticToPrim be ? GetMethod(input, @@toPrimitive).If exoticToPrim is not undefined, thenIf hint is "default", set hint to "number".Return ? OrdinaryToPrimitive(input, hint).Return input.
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 442 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号