I want to seal JavaScript objects as soon as they get created:
'use strict';
class Test {
}
const t = Object.seal(new Test());
t.p = true; // error!
Is there a way to do it automatically, something like below?
Test.sealInstances = true // I wish sealInstances was real!
const t = new Test();
t.p = true; // error
I know I could do this:
function createTest() {
return Object.seal(new Test())
}
and use createTest everywhere but I'd like the new Test() syntax more.