簡體   English   中英

將動作分配給變量

[英]Assigning actions to a variable

在回答Aaron 最近的問題時,我想做以下事情:

rule first_rule {
    select when pageview "exampley.com/\?name=(.*)" setting (username)
    pre {
        isjoe = username eq "joe";
        myaction = defaction() {
            thisaction = isjoe => notify("Hello, World", "Hi there, Joe!") | noop();
            thisaction();
        };
    }
    {
        notify("Will it work?", "Methinks you are #{username}");
        myaction();
    }
}

然而,反抗似乎從來沒有奏效。 它不喜歡我試圖將一個動作分配給一個變量然后返回該變量。

我究竟做錯了什么?

你真的很親近。

在反抗結束之前,您不能采取行動。 您需要創建一個延遲執行,直到正確的時間。

改變:

thisaction = isjoe => notify("Hello, World", "Hi there, Joe!") | noop();

thisaction = isjoe => defaction(){notify("Hello, World", "Hi there, Joe!");} | noop;

請注意添加的缺陷,我從noop中刪除了括號。

這個概念類似於 javascript 閉包。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM