class A function f(x) x + 1 (function(obj) obj.f(1))(new A) class B function g(f) f(1) (new B).g(function(x) x + 1)