Why is an error reported here? It works fine in js
# getting-started
a
Why is an error reported here? It works fine in js
v
Because Kotlin is not JS
👆 3
😂 1
Ohter language, other rules.
💯 1
Even if you in the end cross-compile to JS
e
the name isn't bound until after the declaration. this allows for things like
Copy code
fun foo(x: Int?) {
    val x: Int = x ?: default
the
x
on the right-hand side refers to the
x
from the outer scope, the left-hand side
x
doesn't exist yet.
v
Not that you should do such shadowing 😄
e
also it would be unsafe in Kotlin to allow that, for example
Copy code
val x = run { x }
to write a self-referential lambda, you need to use an object expression,
Copy code
val obs = object : () -> Unit {
    override fun invoke() {
        signalApplyCallback = this
    }
}
note that the name
obs
still isn't bound yet, but you can refer to the lambda itself as
this
a
Thanks