This is a
playground to test code. It runs a full
Node.js environment and already has all of
npm’s 400,000 packages pre-installed, including
restrict-globals with all
npm packages installed. Try it out:
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.
restrict-globals allows you to prohibit certain functions from accessing specific global variables. The restricted function will not have read nor write access to the variables when it is called. This can be useful for calling functions that you don't want to access the DOM, the JQuery object, the console object, and more.
When restrict-globals.js is put onto the page, it will create a global function called
callWithoutGlobals, whose usage is described below.
restrict-globals module exports a single function whose usage is described below
callWithoutGlobals function (or the exported function in NodeJS) allows for four parameters:
globalsToRestrict(required): This is an array of strings, each element being the name of a global variable that you don't want the function to have access to
funcToCall(required): The function to call
funcArguments(optional): An array of arguments to be passed to the function
funcThisArg(optional): The context or thisArg to be passed to the function
See test/test.js for examples on how to use.