Fork me on GitHub
#clojurescript
<
2022-07-05
>
pinkfrog02:07:31

Hi. I wonder why the first does not work. And how is it compiled to js.

;; ; Cannot read properties of undefined (reading 'lineAt')
(let [editor ^js vscode/window.activeTextEditor]
  (.lineAt editor.document
           vscode/window.activeTextEditor.selection.active.line))

(let [editor ^js vscode/window.activeTextEditor]
  (.lineAt (.-document editor)
           vscode/window.activeTextEditor.selection.active.line))

pinkfrog02:07:20

Background: This happens when I am writing joyride script.

pez06:07:40

I don’t know why these behave differently. But since this is #joyride the code is never compiled to JavaScript. It's interpreted by #sci .

pinkfrog06:07:47

It seems like ts/js now has default arguments. Is it possible in cljs? For example, vscode api has default arguments.

p-himik06:07:32

It has been possible for a long time:

(defn f [{:keys [a b c] :or {b :some-default-value}}]
  ...)

p-himik06:07:03

Or:

(defn f
  ([a b] (f a b :default-c))
  ([a b c] ...))

pinkfrog07:07:39

That is about native cljs. I am asking about interop with js default arguments.

p-himik07:07:26

I don't think there's any special interop need for this. If you have e.g. function f(a, b=1) {} in JS and call it as (f 3) from CLJS, it should use the default value.

pinkfrog07:07:36

what about function f(a=0,b=1) and call it in cljs with the intention of only supplying the value of b?

pez07:07:53

You can't do that in JS, can you?

p-himik07:07:41

You can, by supplying undefined. In CLJS, that would be js/undefined.

pinkfrog07:07:03

> You can’t do that in JS, can you? Just tested indeed I cannot do that. Then regarding the image I posted (the vscode api, what’s the default value mean since I must specify the arguments anyway?)

pinkfrog07:07:43

I mean I can’t do

pos.translate(characterDelta=3)
and have the lineDelta to be by default zero.

p-himik07:07:00

That's because JS has no named arguments. Just use a positional undefined.

pinkfrog07:07:11

> You can, by supplying undefined. In CLJS, that would be js/undefined. Right.