Groovy Prototype Object
Posted
by Holden
on Stack Overflow
See other posts from Stack Overflow
or by Holden
Published on 2010-02-24T04:40:22Z
Indexed on
2010/03/30
9:03 UTC
Read the original article
Hit count: 504
groovy
|metaprogramming
I have a method with an incoming variable, which represents a script.
e.g.
hello.groovy
Foo.init(this)
Foo.groovy
class Foo {
static init(app) {
}
}
What is the best way to add a ton of new functionality to the app
variable in the init method? Basically, I would like to add all the functionality of another object to the app
object.
For instance, if I had another class:
class Bar {
def a() { }
def b() {
}
}
I would like the app
object to basically be a new Bar()
. In JavaScript, this is easy by using the prototype object, but I cannot seem to get it working in groovy. What is the best way to accomplish this? Or should I be doing something differently?
© Stack Overflow or respective owner