global.foo = function() { console.log('test'); } // Somewhere else in the code foo(); Also, I use my code to check for run functions in the global scope, take a look here to see how I've implemented it: https://github.com/avdg/screeps/blob/04f55ec991bad17772bee6a93b7615f8d731c6cb/scripts/main.js#L31 I simply set a function that sets the global run in the console and it should simply work