Created
March 28, 2014 00:32
-
-
Save getify/9822436 to your computer and use it in GitHub Desktop.
cyclic __proto__ ... disallowed?
This file contains 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
Foo = { baz: 2 /*, .. */ }; | |
// link Bar to Foo | |
Bar = Object.create( Foo ); | |
Bar.bam = 3; | |
// link Foo back to Bar | |
Foo.__proto__ = Bar; | |
// or, in ES6: `Object.setPrototypeOf( Foo, Bar )` | |
// throws error here. | |
// in chrome: "cyclic __proto__ value" | |
// in ff: [[SetPrototypeOf]] failed on ({baz:2}) | |
Bar.baz; // 2 | |
Foo.bam; // 3 |
This file contains 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
If you were to make a property or method reference against | |
`Foo` or `Bar` that didn't exist on either, you'd have a | |
legitimate "infinite recursion" type of error condition. | |
But, it seems like `Bar.baz` and `Foo.bam` are safe and | |
should be allowed, no? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I thought the only why access
Foo.bam
is by mix-in not through prototype inherit.