2

here is my code,running on shadow-cljs.

(ns app.main
  (:require [goog.structs.LinkedMap]))
(extend-type goog.structs.LinkedMap
  cljs.core/IFn
  (-invoke
    ([m k] (.get m k nil))
    ([m k not-found] (.get m k not-found))))

(def m (goog.structs.LinkedMap.))
(.set m 34 :foo)
(println (m 34))

The error message is as follows:#object[TypeError TypeError: app.main.m is not a function]

but I ran (type m), the result is as follow:#object[Function], This is indeed a function.

sample code and eval result

akond
  • 15,865
  • 4
  • 35
  • 55
kin devin
  • 23
  • 3

1 Answers1

1

Hmm this is indeed a problem. A while ago I added an optimization to make function calls for goog.* code faster and produce less code. However this prevents IFn from working properly for those types. All normal protocols work just fine only IFn is an issue.

I'll think about this and see if I can figure out a way to keep both. Please open a shadow-cljs github issue so I don't forget.

The (type m) will get you the Constructor of m which is indeed a function. m is the instance which is not a function.

Thomas Heller
  • 3,842
  • 1
  • 9
  • 9
  • Thanks for your patience, I have opened an issue about this question. https://github.com/thheller/shadow-cljs/issues/742 – kin devin Jun 24 '20 at 09:12