开发者

Ternary operator changing "true" to literal true

开发者 https://www.devze.com 2023-02-22 02:31 出处:网络
I\'m trying to assign a string literal to a variable using a ternary operator with the following code开发者_如何学运维 in the pre block:

I'm trying to assign a string literal to a variable using a ternary operator with the following code开发者_如何学运维 in the pre block:

texta = "approve";
textd = "deny";
aAction = texta eq "approve" => "true" | "false";
dAction = textd eq "approve" => "true" | "false";

However, this is what comes across in the JavaScript:

var texta = 'approve';
var textd = 'deny';
var aAction = true;
var dAction = false;

Notice that aAction and dAction should be strings, but they are actually boolean literals.

Why is this happening?


One way to force it back into a string is with a beesting:

aActionStr = "#{aAction}";
dActionStr = "#{dAction}";

Doesn't answer the question as to why this happens, but it's a hack that will work in this case.

0

精彩评论

暂无评论...
验证码 换一张
取 消