为了解决这个问题: [] + [] === "", 请问下 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.
添加回答
举报
0/150
提交
取消