vaskir
09/27/2018, 9:45 AMdiesieben07
09/27/2018, 9:48 AMvaskir
09/27/2018, 9:50 AMdiesieben07
09/27/2018, 9:50 AMvaskir
09/27/2018, 9:50 AMarekolek
09/27/2018, 9:50 AMvaskir
09/27/2018, 9:50 AMdiesieben07
09/27/2018, 9:53 AMTwo
can reference local variables declared in Foo
?One
before the declaration of Two
?vaskir
09/27/2018, 9:53 AMactor { }
with a bunch of local functions and oops.diesieben07
09/27/2018, 9:54 AMReferenceError
at runtimefunction asd() {
function one() {
two()
}
one();
const x = 123;
function two() {
console.log(x);
}
}
Will produce Uncaught ReferenceError: x is not defined
.vaskir
09/27/2018, 9:57 AMdiesieben07
09/27/2018, 9:58 AMone
, which calls two
, which then references x
. But at the time you are calling it x
is not even declared or assigned yetvaskir
09/27/2018, 9:58 AMrobin
09/27/2018, 9:59 AMfun foo() {
lateinit var two: () -> Unit
fun one() {
two()
}
two = {
}
one()
}
diesieben07
09/27/2018, 9:59 AMarekolek
09/27/2018, 10:00 AMvaskir
09/27/2018, 10:00 AMdiesieben07
09/27/2018, 10:00 AMOne
before your void Two
declaration, which is the entirety of the problem.arekolek
09/27/2018, 10:01 AMUncaught ReferenceError: x is not defined
.robin
09/27/2018, 10:01 AMdiesieben07
09/27/2018, 10:02 AMlateinit
just brings JS' "explode at runtime" behavior to kotlin.robin
09/27/2018, 10:03 AMdiesieben07
09/27/2018, 10:03 AMrobin
09/27/2018, 10:03 AM!!
then?diesieben07
09/27/2018, 10:04 AM!!
outside of quick and dirty experimental codearekolek
09/27/2018, 10:05 AM!!
is java interop I think, if you have only kotlin, then I don’t see much usediesieben07
09/27/2018, 10:06 AMrobin
09/27/2018, 10:07 AMvaskir
09/27/2018, 10:08 AMdiesieben07
09/27/2018, 10:08 AMx
does not have a constant initializer but is computed? E.g. random number?x
is marked const
and can be inlined by the compiler.vaskir
09/27/2018, 10:10 AMrobin
09/27/2018, 10:10 AMvaskir
09/27/2018, 10:10 AMAndreas Sinz
09/27/2018, 10:10 AMvaskir
09/27/2018, 10:12 AMAndreas Sinz
09/27/2018, 10:13 AMvngantk
12/18/2018, 1:30 AM