Created
October 10, 2013 08:17
-
-
Save tfanme/6914853 to your computer and use it in GitHub Desktop.
JavaScript: value type and reference type
This file contains hidden or 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 str = 'abcde'; | |
| var obj = new String(str); | |
| function newToString() { | |
| return 'hello, world!'; | |
| } | |
| function func(val) { | |
| val.toString = newToString; | |
| } | |
| // sample1: input value | |
| func(str); | |
| alert(str); | |
| // sample2: input reference | |
| func(obj); | |
| alert(obj); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment