JoakimForslund
03/01/2019, 12:40 PMstate
in this code would show as state_v23xwe$_0
in javascript?
@Serializable
data class StateAware(@JsName("id") val id: String = hashCode().toString(), @JsName("test")val test: String = "Tested") {
@JsName("state")
var state: Int = Initilized
set(value) {
println("Item with id:$id -> Old State: '${this.state}' | New State: '$value' has been set")
field = value
stateAwareContainer.sync(this)
}
}
altavir
03/01/2019, 1:10 PMr4zzz4k
03/01/2019, 1:50 PM@get:JsName("getState")
@set:JsName("state")
?Svyatoslav Kuzmich [JB]
03/01/2019, 1:51 PMstate_v23xwe$_0
is likely a backing field
. You will also have state
JS property on the object prototype.JoakimForslund
03/01/2019, 3:19 PMJoakimForslund
03/01/2019, 3:22 PMJoakimForslund
03/01/2019, 3:23 PMSvyatoslav Kuzmich [JB]
03/01/2019, 4:22 PMval state
will be translated to something like:
Object.defineProperty(StateAware.prototype, 'state', {
get: function () {
return this.state_v23xwe$_0;
},
set: function (value) {
// ...
this.state_v23xwe$_0 = value;
// ...
}
})
And on the use-site you can do:
var sa = new StateAware();
sa.state = 10;
What’s not working?JoakimForslund
03/04/2019, 11:28 AM