How to do this in Kotlin-js?

Js code:

function Ctrl(scope, filter) {   scope.a = filter("abc"); }

I tried to write some Kotlin code like this:

native trait Filter { }

native trait Scope {
  var a:String

fun Ctrl(scope:Scope, filter:Filter) {
  scope.a = filter(“abc”)  // !!! how to declare this “()” method in trait Filter?

You can see there is a "filter("abc")", it can be understood as ", "abc")". How to declare a proper method for it?

Looks like a function type would help

Do you mean I should declare "Filter" as:


fun Ctrl(scope:Scope, filter: (String)->String) {}

But the “filter” may have other methods, e.g. filter.hello()

What should I do for this case?

Define a mwthod named invoke(). See this page: