mail
privacy

I recently started developing with NodeJS and noticed something peculiar:

var a = {"test": "moo"}; // Define an object
var b = a; // Copy the object
b.test = "meh";
alert(a.test); // alert: "meh"
// wait- what? b = a makes a reference instead of a copy, doh!

One way to get around this is:

var b = JSON.parse(JSON.stringify(a)) // This is one ugly hack

but it feels.. wrong.. and probably doesn’t work with nested functions and stuff like that.Thinking

Related posts:

  1. Was man mit JavaScript alles machen kann..
language
Tagged with:
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

language