How do you reference javascript's this keyword from clojurescript?

前端 未结 1 2259
梦谈多话
梦谈多话 2021-02-20 13:06

I\'m integrating some ClojureScript code with a JS library call that takes a callback function. The JS library passes data to the callback using JavsScript\'s \"this\" keyword.

1条回答
  •  时光取名叫无心
    2021-02-20 13:39

    Use the built-in this-as macro. It takes a name and a body, and evaluates the body with the name bound to JavaScript this.

    e.g.

    (libraryCall (fn [] (this-as my-this (.log js/console my-this))))
    

    Great question... had to dig into the compiler code to find it, it's not well advertised at all.

    I'll add it to the book.

    0 讨论(0)
提交回复
热议问题