Is there any way to obtain a this reference to a l...
# announcements
h
Is there any way to obtain a this reference to a lambda from within itself? Usecase:
Copy code
val cb ={ event: SomeEventType ->
                 // Do stuff on event
                 callbackList.remove( /* How to obtain reference to self*/)
        }
        callbackList.add(cb)
        // Do stuff that will trigger cb in the list to be called
Think of a list of one-time callbacks.
h
r
I haven't tried but I guess you could achieve it with a
var self
which is initially
null
. Use it inside cb and assign cb to self afterwards. Should work no? Ugly though
h
Works, but ugly, yes