I do a lot of Sass code reviews. Along the same lines, I like to read frameworks' code. Needless to say, I have seen a lot of things, both good and bad, when it comes to Sass.
If there is something that always make me grind my teeth when I read other people's Sass, it's seeing mixins and functions using lists instead of variable arguments, or using lists instead of multiple named arguments.
In this article I'd like to take a look at this issue and, hopefully, show when to use what more clearly.
Terminology
Before going any further let's have a quick look at the terminology. Both functions and mixins are able to accept arguments, from 0 to infinity. That means you can make an argument-less function/mixin or one with a multitude of arguments. Now let's go deeper.
In Sass, a list
is the equivalent to an array in other languages. A value that happens to have list
as a type (checked with the type-of
function) is a collection of several values that have a specific type (number
, string
, bool
, color
, list
, map
or null
). For a deeper understanding of Sass lists, I suggest you read my article about this.
Last but not least, there is a variable argument. You may not have known that arglist
is an actual Sass data type (it's mentioned nowhere in the docs). The thing is, you cannot easily create an arglist
(deliberately) because it is usually an internal mecanism from Sass which happens when you use the variable argument notation within a mixin/function signature.
For instance:
Continue reading %Sass Multiple Arguments, Lists or Arglist%
by Hugo Giraudel via SitePoint
No comments:
Post a Comment