I want to get a JavaScript object loaded into a Kotlin class. As a safety check, I need to verify that the Kotlin object is actually the class I’ve created because some JavaScript code parts are not my design. I need the JavaScript to return correctly, but I cannot verify the Kotlin class.
e.g.
JavaScript object
<script id="myJS">
function MyClass(id, name){
var obj = {};
obj.id = id;
obj.name = name;
return obj;
}
var myClass = MyClass(0, "name_0");
</script>
Kotlin class
class MyClass(
val id: Int,
val name: String
)
I use this Kotlin code to get JavaScript object on Kotlin.
val myJS: dynamic = document.getElementById("myJS")
val myClass: MyClass = JSON.parse<MyClass>(JSON.stringify(myJS.myClass))//get JavaScript object
println(myClass.id)//success output "0"
println(myClass.name)//success output "name_0"
println(myClass is MyClass)//but check class this output "false"
How can I verify the JavaScript object is the created Kotlin class?