Created
April 15, 2012 20:19
-
-
Save angus-c/2394659 to your computer and use it in GitHub Desktop.
ToPrimitiveNoHint.js
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
//shim of ES5.1 internal ToPrimitive method | |
//see http://es5.github.com/#x9.1 | |
//assumes no hint argument (as is the case with == operands) | |
var ToPrimitiveNoHint = function(value) { | |
if (typeof value != 'object') { | |
return value; | |
} | |
if (typeof value.valueOf() != 'object') { | |
return value.valueOf(); | |
} | |
if (typeof value.toString() != 'object') { | |
return value.toString(); | |
} | |
throw Error("can't convert a to primitive type"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment