F
F
ff0xff2019-03-09 15:44:54
Node.js
ff0xff, 2019-03-09 15:44:54

Why is object proxying not working in nodejs?

Tell me why, when writing in file B, the proxy in file A does not react?
A

'use strict'

const ws = require('./b');

var data_store = [];

var proxy = new Proxy(data_store, {
    set(target, prop, value) {
        console.log(`Запись ${prop} ${value}`);
        target[prop] = value;
        return true;
    }
});

exports.proxy = proxy;

B
const proxy = require('./a');

console.log(proxy);
function handle() {
    proxy['asd'] = 'asd';
    console.log('write');
}
handle();

The whole day I'm trying to understand what's the matter and not how I can't do it, if you write everything in one file, then everything is ok. Tell me what the trouble can be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-03-09
@ff0xff

The import is incorrect. Replace with
const proxy = require('./a').proxy;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question