What is the most effective method to determine the specific parent object of a property when dealing with an object that has multiple prototype parents and a known property name implemented on one of them?
For example:
var a = { x: 'foo' };
var b = {};
var c = { y: 'bar' };
var d = { z: 'baz' };
var e = {};
b.__proto__ = a;
c.__proto__ = b;
d.__proto__ = c;
e.__proto__ = d;
alert(e.y); // 'bar'
If we only have a reference to e
, our goal is to identify c
as it is the origin of the value assigned to
e.y</code. The number of levels between <code>c
and e</code can vary.</p>
<p>(To provide context, in reality <code>e
represents an AngularJS $scope
, therefore this question also pertains to identifying the parent scope that delivers a particular inherited scope property.)