anyone has idea why this compile error? when const...
# javascript
t
anyone has idea why this compile error? when const in javascript is used wherever in js(), say like
Copy code
js("const value = 5;")
it will complain
missing ; before statement
, is this a bug or I have some misunderstanding
a
I'm not sure that the ES2015 syntax is supported inside the
js
function. Will it complain if you replace the
const
with
var
?
t
hmmm it work in above case, but in my actual case
Copy code
@JsName("audioPlay")
fun audioPlay(url: String){
    js("""
            var context = new AudioContext();
            var source = context.createBufferSource();
            var audioBuffer = await fetch(url)
                .then(res => res.arrayBuffer())
                .then(ArrayBuffer => context.decodeAudioData(ArrayBuffer));
    
            source.buffer = audioBuffer;
            source.connect(context.destination);
            source.start();
    """)
}
it will complain the same error at the line of
var audioBuffer = ...
, maybe it can't be assigned for function
a
await
is also es2015+ syntax
🫡 1
Try to run this:
Copy code
var context = new AudioContext();
var source = context.createBufferSource();
fetch(url)
  .then(function (res) { return res.arrayBuffer() })
  .then(function (ArrayBuffer) { return context.decodeAudioData(ArrayBuffer) })
  .then(function (audioBuffer) {
    source.buffer = audioBuffer;
    source.connect(context.destination);
    source.start();
  });
gratitude thank you 1
t
It can be written in Kotlin/JS without redundant workarounds
🫡 1
Fine
AudioContext
is here
thank you color 1
With coroutines you can use suspend fetch
thank you color 1
t
oohhh, thank you guys alot! these are all I need to know!
t
FYI - All stable browser API you can find in
kotlin-browser
👌 1