```class TemplateParser : StreamParser { overr...
# javascript
p
Copy code
class TemplateParser : StreamParser {
    override fun token(stream: StringStream, state: dynamic): String? {
        console.log(stream, state)
        return null
    }
}
This gets compile to this JS:
Copy code
function TemplateParser() {}
    TemplateParser.prototype.token_qt5re9_k$ = function(stream, state) {
        console.log(stream, state);
        return null;
    }
    ;
    TemplateParser.prototype.token = function(stream, state) {
        return this.token_qt5re9_k$(stream, state);
    }
    ;
Which crashes with
Uncaught TypeError: this.token_qt5re9_k$ is not a function
WTF?!
s
token
is probably called without an object instance:
Copy code
> var tp = new TemplateParser();
undefined
> tp.token("A", "B")
A B
null
> var token = tp.token
undefined
> token("A", "B")
Uncaught TypeError: this.token_qt5re9_k$ is not a function
    at TemplateParser.token (REPL9:2:21)
p
It's used in a library, so I don't know how they are using it. But I rewrote it from
class
to just simple
jsObject
of that interface with
var token
and lambda, it's working.
s
Another possible workaround is using property with a function type:
Copy code
external interface StreamParser {
    val token: (stream: StringStream, state: dynamic) -> String?
}

class TemplateParser : StreamParser {
   override val token = fun (stream: StringStream, state: dynamic): String? {
       …
    }
}