According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/Proxy/set#return_value
If the
set()
method returnsfalse
, and the assignment happened in strict-mode code, a TypeError will be thrown.
The following code throws.
(function () {
"use strict";
const proxy = new Proxy({}, {
set(target, property, value) {
}
});
proxy.foo = 'bar'
})()
// Uncaught TypeError: 'set' on proxy: trap returned falsish for property 'foo'
This rule enforce the set
to explicitly return true
.
This rule also allow return Reflect.set()
call.
const proxy = new Proxy({}, {
set(target, property, value) {
target[property] = value;
}
});
const proxy = new Proxy({}, {
set(target, property, value) {
target[property] = value;
return 1; // Will work, but should be `true` to be clear.
}
});
const proxy = new Proxy({}, {
set(target, property, value) {
target[property] = value;
return true;
}
});
const proxy = new Proxy({}, {
set(target, property, value) {
return Reflect.set(...arguments);
}
});
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too