this-as behaves incorrectly in "scoping function"

Description

When a this-as expression gets put in a "scoping function", e.g. in a let-binding, the value bound via this-as refers to the scoping function, and not to the outer scope.

Example:

1 2 3 4 5 6 7 8 9 10 (def foo (js-obj "bar" "baz" "getBarRight" (fn [] (this-as self (.-bar self))) "getBarWrong" (fn [] (let [bar (this-as self (.-bar self))] bar)))) (.log js/console (.getBarRight foo)) ;; => "baz" (.log js/console (.getBarWrong foo)) ;; => undefined

Whereas foo.getBarRight expands to something like

1 2 3 4 function() { var self = this; // this refers to foo return self.bar; // returns "bar" }

foo.getBarWrong on the other hand expands to

1 2 3 4 5 6 7 function() { var bar = function() { var self = this; // this refers to enclosing function return self.bar; // returns undefined }(); return bar; // returns undefined }

Environment

None

Status

Assignee

David Nolen

Reporter

import

Labels

None

Approval

None

Patch

None

Fix versions

Affects versions

1.7.145

Priority

Major
Configure