Prior to construct an instance of class Foo, I would like to create an instance method object of a method defined in class Foo and assign it to a variable. I would then create an instance of class Foo, and execute the instance method object via the variable against the newly created instance. Is this doable? If so, how? Thanks.
Share
I hope I understood correctly that you want something like this:
Yes, this is possible.
Foo.speakis an unbound method, which is a callable (function) that can be passed an instance as its first argument to obtain the same behavior that you’d get from a bound method such asFoo("hello").speak.