Skip to content

Instantly share code, notes, and snippets.

@cloudhead
Created February 28, 2012 16:51
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloudhead/1933613 to your computer and use it in GitHub Desktop.
Save cloudhead/1933613 to your computer and use it in GitHub Desktop.

Variadic argument support in LESS 1.3.0

.mixin (...) {        // matches 0-N arguments
.mixin () {           // matches exactly 0 arguments
.mixin (@a: 1) {      // matches 0-1 arguments
.mixin (@a: 1, ...) { // matches 0-N arguments
.mixin (@a, ...) {    // matches 1-N arguments

Furthermore:

.mixin (@a, @rest...) {
   // @rest is bound to arguments after @a
   // @arguments is bound to all arguments
}
@fat
Copy link

fat commented Mar 25, 2012

@arguments concats varargs as a single string (which is why there are no commas). the above is interpreted as two seperate variables - not 1 comma delimited var. You could do this:

.element {
  .box-shadow(~"0 1px 2px rgba(0,0,0,.1), inset 0 2px 3px rgba(0,0,0,.075)");
}

Because of this, doesn't seem like we're getting anything from the @arguments var... just use @shadow

@mdo
Copy link

mdo commented Mar 25, 2012

Ahhh, yes didn't even think about that at the time. <3

@bartt
Copy link

bartt commented Mar 26, 2012

That works, but I find it rather counter intuitive with mixins that provide a uniform facade to browser specific prefixes such as .box-shadow above.

@petrbrzek
Copy link

Markdotto: You can do this.

.lol(@arg...){
  background: ~`"@{arg}".replace("]","").replace("[","")`;
}
.lol(hi,lol,rofl);

result: background: hi, lol, rofl;

@himynameisdave
Copy link

Very useful reference, even from 2014.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment