Skip to content

Instantly share code, notes, and snippets.

@dandean
Created June 17, 2011 00:18
Show Gist options
  • Save dandean/1030631 to your computer and use it in GitHub Desktop.
Save dandean/1030631 to your computer and use it in GitHub Desktop.
Object#valueOf is fucking awesome
var thing = {
data: [1, 2, 3],
valueOf: function() {
var result = 0;
this.data.forEach(function(x) {
result += x;
});
return result;
}
};
thing + thing
// -> 12
thing * thing
// -> 36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment