Currently trying to make a custom implementation of Array / Object (Would end up being pretty similar i suppose) and have stumbled upon an issue that is driving me crazy.
As you can see, b is only an instanceOf Array, even though its created from custom class CachedArray, thus my custom function testPush is not defined, and i cant for the sake of everything find what is the issue.
Using Nodejs 6
function _setKey(target, key, value) {
console.log('Setting value', key, 'to', value);
target[key] = value;
return true;
}
class ExtendableProxy {
constructor(a, b) {
return new Proxy(a, b);
}
}
class CachedArray extends ExtendableProxy {
constructor(redis, options) {
let RawArray = [];
super(RawArray, {
set: _setKey
});
this._rawArray = RawArray;
this.redis = redis;
this.options = options;
}
testPush() {
this.push('Its me');
}
}
var b = new CachedArray();
console.log('b instanceof CachedArray', b instanceof CachedArray); //false
console.log('b instanceof ExtendableProxy', b instanceof ExtendableProxy); //false
console.log('b instanceof Proxy', b instanceof Proxy); //false
console.log('b instanceof Array', b instanceof Array); //true
b.push('Hello.'); //Works just fine, _setKey is called and executed correctly
b.testPush(); //TypeError: b.testPush is not a function