In javascript
- Strings and primitive types (logical and numeric) are passed by value
- Objects, arrays and functions are passed by reference
As a name, the string name: _name save the current value of _name , not a link to _name .
setName in your example will only change _name .
getName will access _name , which contains the current value.
.name will access the copied value that was set during initialization ( name: _name ).
See also SO: Javascript by reference or by value
source share