shama
04/25/2020, 8:24 PMopen class Animal {
open var name: String = "frank"
}
@JsExport
class Bear : Animal {
constructor(): super()
}
In the JS I would expect the following to work:
const bear = new Bear()
bear.name === "frank"
But bear.name
is undefined
. Looking at the JS output, the Animal
class has the getters/setters but never defines the name
property.
Not until I add @JsExport
to the Animal
class in Kotlin. The name
property will now appear in the JS code but bear.name
is still undefined
.
It seems because the Bear
class doesn’t call the Animal
constructor so the underlying property this._name
never gets initialized. I would expect the following to be in the JS output to match the constructor(): super()
call:
function Bear() {
Animal.apply(this, Array.prototype.slice.call(arguments));
}
Adding that to the JS output gives me my expected result: const bear = new Bear(); bear.name === "frank"