Hi! I ran into some issues with how classes get tr...
# javascript
s
Hi! I ran into some issues with how classes get translated into JS with Kotlin 1.4-M1. If I have the following Kotlin:
Copy code
open class Animal {
    open var name: String = "frank"
}

@JsExport
class Bear : Animal {
    constructor(): super()
}
In the JS I would expect the following to work:
Copy code
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:
Copy code
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"