Skip to content

Instantly share code, notes, and snippets.

@incompl
Created October 17, 2011 14:34
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 incompl/1292727 to your computer and use it in GitHub Desktop.
Save incompl/1292727 to your computer and use it in GitHub Desktop.
.name property, constructors, inheritance
// A weird bug when you inherit from a constructor. You shouldn't
// inherit from a constructor but when I accidentally did I noticed
// this weirdness.
function Foo() {}
// this should be Object.prototype, or {}, or omitted completely,
// but certainly not the Object constructor. Still, what follows
// isn't exactly what you'd expect...
Foo.prototype = Object;
var foo = new Foo();
function Bar() {}
Bar.prototype = foo;
var bar = new Bar();
// This only happens with the name property, and is likely
// related to how constructors (functions) have their name
// set in a special way.
bar.name = 'hello';
bar.name // 'hello' in chrome, 'Object' in firefox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment