How to modify a function in another function in one function?

suppose I have a piece of code now

function globalActions(){
  App = function(obj) {
    console.log("This is a global App, app id is " + obj.id);
  }
  Page = function(obj) {
    console.log("This is a global Page, page id is " + obj.id);
  }
  App({id: "app"});
  Page({id: "page"});
  myGlobalActions();
}
function pluginActions(){
  let originalMyPluginActions = myPluginActions;
  myPluginActions = function(){
    App = undefined
    Page = function(obj) {
      console.log("This is a plugin Page, page id is " + obj.id);
    }
    originalMyPluginActions.apply(this, arguments);
  }
}
function myGlobalActions(){
  myPluginActions(App, Page);
}
function myPluginActions(){
  let originalApp = arguments[0];
  let originalPage = arguments[1];
  arguments[0] = function() {
    console.log("hello I try to modify the global App fn");
    return originalApp.apply(this, arguments);
  };
  arguments[1] = function() {
    console.log("hello I try to modify the global Page fn");
    return originalPage.apply(this, arguments);
  };
}
pluginActions();
globalActions();

it is forbidden to define App or Page (App = / Page =) in myGlobalActions. Only myGlobalActions and myPluginActions, can be modified. Could you tell me how to modify App and Page? in globalActions?

Mar.23,2021

if you provide the condition, it cannot be modified. In technical terms, this is the private property of the globalActions function and cannot be modified externally.


dynamically change variables within a block-level scope. You can only implement

with closures.
Menu