较少关于受保护的mixin的文档-为什么此规则不匹配任何mixin? [英] LESS docs on guarded mixins -- why will this rule not match any mixins?

查看:46
本文介绍了较少关于受保护的mixin的文档-为什么此规则不匹配任何mixin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编写CSS时主要使用SASS,因此我现在也准备尝试LESS.仔细阅读文档后,在保护的上下文中,我对以下内容感到困惑mixins :

Having primarily used SASS when writing CSS, I am now preparing to try out LESS as well. Having a read through the docs, I'm confused with the following in the context of guarded mixins:

此外,关键字true是唯一的真实值,因此 相当于两个mixins:

Additionally, the keyword true is the only truthy value, making these two mixins equivalent:

.truth (@a) when (@a) { ... }
.truth (@a) when (@a = true) { ... }

除关键字true以外的任何值都是虚假的:

Any value other than the keyword true is falsy:

.class {   
  .truth(40); // Will not match any of the above definitions.
}

为什么truth(40)不匹配第一个mixin? when (@a)是否不简单地声明仅在@a存在的情况下将值(任何值)赋给@a才匹配mixin?既然40是一个存在的值,为什么它在给定的mixins中找不到匹配项?

Why will truth(40) not match the first mixin? Doesn't when (@a) simply state that only match the mixin if a value (any value) is given to @a, essentially, if @a exists? And since 40 is a value that exists, why would it not find a match in the given mixins?

推荐答案

为了简洁...

...我想. LESS的程序员似乎假设,如果您不希望在mixin上使用 guard ,那么您当然根本就不会放置任何when语句:

For Conciseness...

...I think. It appears to be assumed by the programmers of LESS that if you do not want a guard on the mixin, then you of course put no when statement at all:

.truth(@a) { ... }

无论@a的值如何,都将调用此mixin,但是需要@a设置值,因此默认情况下也会检查值的存在".因此,通过防护的添加,他们已经假定确实确实打算使用进一步的防护(而不仅仅是允许任何值),等等.

This mixin is called regardless of the value of @a, but does require a value for @a, and so is checking by default for "existence" of a value. So by the adding of a when guard, they have assumed one does indeed intend a further guard (and not just to allow any value), and so...

.truth (@a) when (@a) { ... }

...为编写保护语句提供了一种简写方式(LESS旨在加快编码速度)...

...makes for a shorthand way (LESS is about trying to speed coding) of writing the guard statement...

.truth (@a) when (@a = true) { ... }

这样可以更快地编码仅用于警卫队的true/false开关,并且如果将when (@a)评估为任何值的true似乎是多余的,这似乎是一个很好的理解.

This makes for faster coding of a mere true/false switch for a guard, and probably seemed to be good sense over what would otherwise be a redundant statement if it instead evaluated the when (@a) as true for any value.

从典型的编程角度看,如果@a 存在(例如,除了false之外的任何东西, null0),则短语when (@a)将评估为true.但是,他们没有检查值的存在",而是进行了 explicit 检查,以检查 passed 值是否为true(它们唯一的真实值"为就警卫而言).

It is, admittedly, a bit less intuitive (no pun intended) from a typical programming viewpoint where it would seem that if @a exists (as in, anything other than false, null, or 0) then the phrase when (@a) would evaluate to true. But instead of checking for "existence" of a value, they have made that check an explicit check for a passed value of true (their only "truthy value" as far as guards are concerned).

除了在lesscss.org上关于它们如何编码的声明外,我没有任何文档可以在这里备份我的声明,但没有说明为什么. >他们将其编码为这种方式工作(那部分是我目前的推测,除非我能找到有关此问题的讨论文档).

I don't have any documentation to back up my statements here, other than the statements on lesscss.org about how they have coded it, which state nothing about why they coded it to work that way (that part is my speculation at present, unless I can track down documentation of discussion about it).

这篇关于较少关于受保护的mixin的文档-为什么此规则不匹配任何mixin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆