Skip to content

Instantly share code, notes, and snippets.

@getify
Created March 28, 2014 00:32
Show Gist options
  • Save getify/9822436 to your computer and use it in GitHub Desktop.
Save getify/9822436 to your computer and use it in GitHub Desktop.
cyclic __proto__ ... disallowed?
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
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?
@yuanyan
Copy link

yuanyan commented Mar 29, 2014

I thought the only why access Foo.bam is by mix-in not through prototype inherit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment