Created
February 10, 2017 07:17
-
-
Save hisasann/9fc86b7e48f4505fbde20ffe64a1ba05 to your computer and use it in GitHub Desktop.
I can hook ToPrimitive method!
This file contains 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
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