Skip to content

Instantly share code, notes, and snippets.

@sramam
Created January 30, 2014 17:44
Show Gist options
  • Save sramam/8714322 to your computer and use it in GitHub Desktop.
Save sramam/8714322 to your computer and use it in GitHub Desktop.
Javascript passing by copy of reference, a simple test across closure.
var CL = function(){
config = {
field: {
key: []
}
},
add_val = function(val) {
config.field.key.push(val)
}
return {
get_key : function() {
return config.field.key
},
add_val: add_val,
list_vals: function() {
return config.field.key
}
}
}
cl = CL()
srvr = cl.get_key()
srvr.push('#1')
cl.add_val('#2')
console.log(srvr)
console.log(cl.list_vals())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment