Reputation: 185
I am creating interactive infographics using Google Charts and Kotlin JS. This is snippet from Quick Start Page.
var data = new google.visualization.DataTable();
<..>
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
Here "new" keyword is used. I tried to rewrite this code using Kotlin.
val data = google.visualization.DataTable();
<..>
val chart = google.visualization.PieChart(document.getElementById('chart_div'));
But an error occurred saying that "new" keyword is missing in lines above. So Kotlin to JS compiler haven't added the keyword where they should be. Here is compiled JavaScript code.
var data = google.visualization.DataTable();
<..>
var chart = google.visualization.PieChart(document.getElementById('chart_div'));
Is there correct way to avoid the error without using js() function?
Thank you.
Upvotes: 1
Views: 200
Reputation: 185
The reason why the new
keyword was not added is because google
variable hadn't been added with external
keyword. With this one Kotlin generates correct code.
external object google {
object visualization {
class DataTable
}
}
Upvotes: 2