Created
May 24, 2013 14:32
-
-
Save jlank/5643931 to your computer and use it in GitHub Desktop.
from http://dmitrysoshnikov.com/ecmascript/chapter-7-2-oop-ecmascript-implementation/ -- good explanations across the board
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 = { | |
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