Uploaded image for project: 'ClojureScript'
  1. CLJS-1123

this-as unexpectedly binds js/window when used within function with post-condition

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects versions: None
    • Fix versions: None
    • Labels:
      None

      Description

      Adding a post-condition to any function that uses cljs.core/this-as will unexpectedly cause this-as's "this" symbol to be bound to the root object (e.g., js/window) instead.

      (defn f-no-post-condition [argument]
        (this-as this
          (js/console.log argument this)))
      
      (defn f-with-post-condition [argument]
        {:post [true]}
        (this-as this
          (js/console.log argument this)))
      
      (def test-object
        #js {:methodNoPostcondition f-no-post-condition
             :methodWithPostcondition f-with-post-condition})
      
      (f-with-post-condition "A") ; Correctly prints js/window
      (.methodNoPostcondition test-object "B") ; Correctly prints test-object
      (.methodWithPostcondition test-object "C") ; Incorrectly prints js/window
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: