find-value-locations
v2.0.5
Published
Given an object, and a value, return a tuple of the property name, and the object on which it is an own property.
Downloads
6
Maintainers
Readme
find-value-locations
Given an object, and a value, return a tuple of the property name, the object on which it is an own property, and the property descriptor.
Works with string keys, Symbol keys, both enumerable and non-enumerable keys, and crawls up the prototype chain to find the exact object it's located on.
Example
var findValue = require('find-value-locations');
var assert = require('assert');
var value = {};
function Foo() {}
function Bar() {}
function Baz() {}
Object.prototype.property = value;
Function.prototype.property = value;
Bar.prototype = Baz;
Foo.prototype = new Bar();
Foo.prototype.property = value;
var symbol = Symbol('a symbol property');
Foo.prototype[symbol] = value;
var tuples = findValue(new Foo(), value);
assert.deepEqual(tuples, [
[Foo.prototype, 'property', Object.getOwnPropertyDescriptor(Foo.prototype, 'property')],
[Foo.prototype, symbol, Object.getOwnPropertyDescriptor(Foo.prototype, symbol)],
[Function.prototype, 'property', Object.getOwnPropertyDescriptor(Function.prototype, 'property')],
[Object.prototype, 'property', Object.getOwnPropertyDescriptor(Object.prototype, 'property')]
]);
Tests
Simply clone the repo, npm install
, and run npm test