Skip to content

Instantly share code, notes, and snippets.

@hisasann
Created February 10, 2017 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hisasann/9fc86b7e48f4505fbde20ffe64a1ba05 to your computer and use it in GitHub Desktop.
Save hisasann/9fc86b7e48f4505fbde20ffe64a1ba05 to your computer and use it in GitHub Desktop.
I can hook ToPrimitive method!
var a = {
x: 1,
[Symbol.toPrimitive]: function(type) {
console.log('called toPrimitive, type: ', type);
return this.x;
}
};
Number(a);
var b = {
x: 'a',
[Symbol.toPrimitive]: function(type) {
console.log('called toPrimitive, type: ', type);
return this.x;
}
};
String(b);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment