|
|
| P is for Practical | |
| PerlMonks |
Generating similar functions in unrelated objectsby t'mo (Pilgrim) |
| on Aug 31, 2001 at 02:03 UTC ( #109219=note: print w/ replies, xml ) | Need Help?? |
|
Suppose you wanted to do something like this to a family of related objects. How would you assign the anonymous function to be a method of each class? (I can do that trick in JavaScript using ObjectName.prototpye.methodName, but how would I do that in Perl?) For example, what I would like to do is:
Then I would use it like this:
The obvious answer here is to use Inheritance™, but what if, for some reason, I don't want to use inheritance? Can I still accomplish what I want to?
In Section
Meditations
|
|
||||||||||||||||||||||||||