You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe. toPrimitive function should return a primitive representation of value provided as a single argument. Coercion hint is bonded to default. Before the Symbol.toPrimitive existed, there were Object.prototype.valueOf and Object.prototype.toString methods that were responsible for returning the primitive value. The function can throw TypeError if Symbo.toPrimitive method returns non primitive value.
Describe the solution you'd like
Possible implementation of toPrimitive:
consttoPrimitive=toPrimitiveHint('default');
Possible implementation of toPrimitiveHint:
// pseudocodeconsttoPrimitiveHint=curry((hint,obj)=>{// if obj is already primitive value, we do nothing is(isPrimitive(obj)){returnobj;}// The order here is very important, it is the order how implicit ToPrimitive coercion works// 1.) find out if obj have Symbo.toPrimitive and call it and return// 2.) find out if obj have valueOf method and call it and return// 3.) find out if obj have toString method and call it and return// 4.) return original object if it cannot be coerced});
Describe alternatives you've considered
toPrimitiveHint should be implemented too as part of this issue. This function consumes the hint of the coercion.
Is your feature request related to a problem? Please describe.
toPrimitive
function should return a primitive representation of value provided as a single argument. Coercion hint is bonded todefault
. Before theSymbol.toPrimitive
existed, there wereObject.prototype.valueOf
andObject.prototype.toString
methods that were responsible for returning the primitive value. The function can throw TypeError ifSymbo.toPrimitive
method returns non primitive value.Describe the solution you'd like
Possible implementation of
toPrimitive
:Possible implementation of
toPrimitiveHint
:Describe alternatives you've considered
toPrimitiveHint
should be implemented too as part of this issue. This function consumes the hint of the coercion.Additional context
This issue is currently blocked by isPrimitive, which is implementation requirement for this function.
valueOf: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/valueOf
Primitive values: https://developer.mozilla.org/en-US/docs/Glossary/Primitive
Symbol.toPrimitive: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive
Ecmascript abstract ToPrimitive operation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive
You don't know Javascript: https://github.com/getify/You-Dont-Know-JS/blob/9959fc904d584bbf0b02cf41c192f74ff4238581/types-grammar/ch4.md
The text was updated successfully, but these errors were encountered: