Created
October 17, 2011 14:34
-
-
Save incompl/1292727 to your computer and use it in GitHub Desktop.
.name property, constructors, inheritance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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