[link|http://www.beanshell.org/manual/bshmanual.html#Scripted_Objects|http://www.beanshell...#Scripted_Objects]

In BeanShell, as in JavaScript and Perl, method "closures" allow you to create scripted objects. You can turn the results of a method call into an object reference by having the method return the special value this. You can then use the reference to refer to any variables set during the method call. Useful objects need methods of course, so in BeanShell scripted methods may also contain methods at any level. For example:


foo() {
print("foo");
x=5;

bar() {
print("bar");
}

return this;
}

myfoo = foo(); // prints "foo"
print( myfoo.x ); // prints "5"
myfoo.bar(); // prints "bar"

------

Objects rather than classes really.