As far as I know, it is impossible to write functions or variables completely out of scope. You can write them outside the class / object definition. You just need to wrap them in an object. What happens mostly is that instead of binding a function / variable to a given class or object, you bind it to a package. Example:
package test package object inside { def hello = println("Hello from outer space!") class Foo { hello
Now that you create Foo, you should type "Hello from Space!".
Not knowing completely what I was talking about, I could assume that the version of the script you mentioned above works because the script runs in some kind of environment. So imagine that some class loads a script, and then transfers it to an object and runs it. This would mean a situation similar to the one above: the functions are still “owned” somewhere.
Jens egholm
source share