Let’s have the following code:
class TestClass {
fun memberFunction() {}
val memberFunctionReference get() = this::memberFunction
}
fun main(args: Array<String>) {
val a = TestClass()
println(a.memberFunctionReference == a.memberFunctionReference)
}
Result on JS platform: false
Result on JVM platform: true
(I guess that the JVM platform is always right )
The problem is with the JS translation of memberFunctionReference()
:
Object.defineProperty(TestClass.prototype, 'memberFunctionReference', {
get: function () {
return getCallableRef('memberFunction', function ($receiver) {
return $receiver.memberFunction(), Unit;
}.bind(null, this));
}
});
Ie. it always returns a new function instead of caching the result of the first invocation.
This is not a theoretical problem: when passing member function references as React component props, currently there is no way to check for their equality in shouldComponentUpdate()
.
Maybe have you met this problem yet (and do you have a workaround )?