Skip to content

Instantly share code, notes, and snippets.

@wentout
Created January 15, 2021 08:32
Show Gist options
  • Save wentout/456ab21582dde12e73bf56fada6ecce8 to your computer and use it in GitHub Desktop.
Save wentout/456ab21582dde12e73bf56fada6ecce8 to your computer and use it in GitHub Desktop.
An explanation of mixed type for Unknown Arity
'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