Sign Up for Free

RunKit +

Try any Node.js package right in your browser

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:

var restrictGlobals = require("restrict-globals")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

restrict-globals v1.0.0

Call any function without worrying about if it will access globals that you don't want it to

Restrict globals

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.

In the browser

When restrict-globals.js is put onto the page, it will create a global function called callWithoutGlobals, whose usage is described below.


The restrict-globals module exports a single function whose usage is described below


The 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.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free