Skip to content

Instantly share code, notes, and snippets.

@tfanme
Created October 10, 2013 08:17
Show Gist options
  • Select an option

  • Save tfanme/6914853 to your computer and use it in GitHub Desktop.

Select an option

Save tfanme/6914853 to your computer and use it in GitHub Desktop.
JavaScript: value type and reference type
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