zyfuni
03/07/2024, 10:36 AMstatic _createHelper(SubHasher) {
let result = (message, cfg) => new SubHasher(cfg).finalize(message);
result.loadWasm = async () => {
if (!SubHasher.wasm) {
await SubHasher.loadWasm();
}
};
result.outputSize = SubHasher.outputSize;
return result;
}
And I found a official doc, but it not tell me how to invoke MyClass as Function
https://kotlinlang.org/docs/js-interop.html#declare-static-members-of-a-class
In JavaScript you can define members either on a prototype or a class itself:
function MyClass() { ... }
MyClass.sharedMember = function() { /* implementation */ };
MyClass.prototype.ownMember = function() { /* implementation */ };
There is no such syntax in Kotlin. However, in Kotlin we have companion
objects. Kotlin treats companion objects of external
classes in a special way: instead of expecting an object, it assumes members of companion objects to be members of the class itself. MyClass
from the example above can be described as follows:
external class MyClass {
companion object {
fun sharedMember()
}
fun ownMember()
}
Artem Kobzar
03/07/2024, 10:43 AMArtem Kobzar
03/07/2024, 10:43 AMArtem Kobzar
03/07/2024, 10:44 AMzyfuni
03/07/2024, 10:49 AM//js("globalThis.Foo = function () {console.log('hello')}")
//print hello
MyClass()
//also in crypto-js-wasm
await CryptoJSW.MD5.loadWasm()
CryptoJSW.MD5("hello")
//CryptoJSW just is [result] in first block.
I make some edit in the playground. Maybe you could check changes at the time?Artem Kobzar
03/07/2024, 11:05 AMzyfuni
03/07/2024, 1:10 PM