const App = console.log.bind(null, 'Hello') Object.defineProperty(window, 'App', { set: ()=> { console.error("You are not allow to modify App"); } }) const sandbox = (App, Function, window) => { 'use strict'; function a() { 'use strict'; // *** I can only modify codes within this block *** Object.define(window, 'App', {get: console.log.bind(null, 'World') }); // *** I can only modify codes within this block *** } function b() { 'use strict'; App(); } a(); b(); }; sandbox(App, ()=>({}), undefined); |
如果只能改function a,能不能改App的getter?