Created
January 15, 2021 08:32
-
-
Save wentout/456ab21582dde12e73bf56fada6ecce8 to your computer and use it in GitHub Desktop.
An explanation of mixed type for Unknown Arity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const mul = (a) => { | |
const result = (b) => { | |
return mul(a * b); | |
}; | |
result[Symbol.toPrimitive] = () => { | |
return a; | |
}; | |
result.valueOf = () => { | |
return new Number(a).valueOf(); | |
}; | |
return result; | |
}; | |
console.log(mul(1) === 1); // false | |
console.log(mul(1) == 1); // true | |
console.log(mul(1)(2) == 2); // true | |
console.log(mul(1)(2).valueOf() === 2); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment