Skip to content

Instantly share code, notes, and snippets.

@bahmutov
Created June 21, 2014 02:00
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 bahmutov/80369a9870889cd58a15 to your computer and use it in GitHub Desktop.
Save bahmutov/80369a9870889cd58a15 to your computer and use it in GitHub Desktop.
You cannot set prototype of an object created by Object.create(null)
// __proto__ DOES NOT WORK
var foo = Object.create(null);
foo.__proto__ = {
bar: 'bar'
};
foo; // { [__proto__]: { bar: 'bar' } }
foo.bar; // undefined
// __proto__ works
var foo = {};
foo.__proto__ = {
bar: 'bar'
};
foo; // { [__proto__]: { bar: 'bar' } }
foo.bar; // 'bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment