Skip to content

Instantly share code, notes, and snippets.

@jeremyroman
Created June 30, 2011 20:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyroman/1057181 to your computer and use it in GitHub Desktop.
Save jeremyroman/1057181 to your computer and use it in GitHub Desktop.
var f = function() {};
f.prototype.food = { apples: 0, bananas: 0 };
var f1 = new f();
f1.food.apples++;
var f2 = new f();
console.log(f2.food.apples); // 1
This is because the food object is modified in-place, and both instances refer to the same object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment