Skip to content

Instantly share code, notes, and snippets.

@angus-c
Created April 15, 2012 20:19
Show Gist options
  • Save angus-c/2394659 to your computer and use it in GitHub Desktop.
Save angus-c/2394659 to your computer and use it in GitHub Desktop.
ToPrimitiveNoHint.js
//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