Skip to content

Commit

Permalink
Added something about argument-less mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
KittyGiraudel committed Sep 1, 2015
1 parent 40db9df commit 8c7901f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
27 changes: 27 additions & 0 deletions _includes/snippets/mixins/08/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

<div class="code-block">
<div class="code-block__wrapper" data-syntax="scss">
{% highlight scss %}
// Yep
.foo {
@include center;
}

// Nope
.foo {
@include center();
}
{% endhighlight %}
</div>
<div class="code-block__wrapper" data-syntax="sass">
{% highlight sass %}
// Yep
.foo
+center

// Nope
.foo
+center()
{% endhighlight %}
</div>
</div>
8 changes: 8 additions & 0 deletions en/_mixins.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ Another valid example would be a mixin to size an element, defining both `width`
* [A Sass Mixin for CSS Triangles](http://www.sitepoint.com/sass-mixin-css-triangles/)
* [Building a Linear-Gradient Mixin](http://www.sitepoint.com/building-linear-gradient-mixin-sass/)

## Argument-less mixins

Sometimes mixins are used only to avoid repeating the same group of declarations over and over again, yet do not need any parameter or have sensible enough defaults so that we don’t necessarily have to pass arguments.

In such cases, we can safely omit the parentheses when calling them. The `@include` keyword (or `+` sign in indented-syntax) already acts as a indicator that the line is a mixin call; there is no need for extra parentheses here.

{% include snippets/mixins/08/index.html %}

## Arguments list

When dealing with an unknown number of arguments in a mixin, always use an `arglist` rather than a list. Think of `arglist` as the 8th hidden undocumented data type from Sass that is implicitly used when passing an arbitrary number of arguments to a mixin or a function whose signature contains `...`.
Expand Down

0 comments on commit 8c7901f

Please sign in to comment.