Skip to content

Instantly share code, notes, and snippets.

@jlank
Created May 24, 2013 14:32
Show Gist options
  • Save jlank/5643931 to your computer and use it in GitHub Desktop.
Save jlank/5643931 to your computer and use it in GitHub Desktop.
var a = {
valueOf: function () {
return 100;
},
toString: function () {
return '__test';
}
};
// in this operation
// toString method is
// called automatically
alert(a); // "__test"
// but here - the .valueOf() method
alert(a + 10); // 110
// but if there is no
// valueOf method, it
// will be replaced with the
//toString method
delete a.valueOf;
alert(a + 10); // "_test10"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment