2024 Clojure 状态调查! 中分享您的想法。

欢迎!有关此功能的工作方式,请参阅 关于 页面以获取更多信息。

0
ClojureScript
将后置条件添加到任何使用 cljs.core/this-as 的函数中,意外地将 this-as 的 "this" 符号绑定到根对象(例如,js/window)。

{代码:none}
(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") ; 正确打印 js/window
(.methodNoPostcondition test-object "B") ; 正确打印 test-object
(.methodWithPostcondition test-object "C") ; 错误打印 js/window

3 个答案

0

评论者:dnolen

这几乎肯定是 CLJS-719 问题的另一种表现。

0
评论者:thheller_

查看生成的 JavaScript。正如 David 所说,问题是用于获取 :post 条件结果的额外函数。


dummy.f_no_post_condition = (function f_no_post_condition(argument){
var this$ = this;
var G__82157 = argument;
var G__82158 = this$;
return console.log(G__82157,G__82158);
});
dummy.f_with_post_condition = (function f_with_post_condition(argument){
var _PERCENT_ = (function (){var this$ = this;
var G__82161 = argument;
var G__82162 = this$;
return console.log(G__82161,G__82162);
})();


return _PERCENT_;
});
dummy.test_object = {"methodWithPostcondition": dummy.f_with_post_condition, "methodNoPostcondition": dummy.f_no_post_condition};
dummy.f_with_post_condition("A");
dummy.test_object.methodNoPostcondition("B ");
dummy.test_object.methodWithPostcondition("C");
0
参考: https://clojure.atlassian.net/browse/CLJS-1123(由 alex+import 报告)
...