question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mixin return values

See original GitHub issue

Can I set a return value as a color? As in:

.myselector {
   border: 1px solid .custommixin(@colorValue);
}

Just wondering in response to another user’s issue regarding color functions: https://github.com/cloudhead/less.js/pull/488

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Reactions:13
  • Comments:59 (41 by maintainers)

github_iconTop GitHub Comments

2reactions
matthew-deancommented, Mar 29, 2017

@distransient There has been more in-depth discussion around designing solutions for this in: https://github.com/less/less-meta/issues/16.

(Less-meta is a repo for higher-level goal planning for Less.js, rather than individual issues or bug reports.)

2reactions
seven-phases-maxcommented, Apr 12, 2014

Mixins are mixins, we must not conflate their usage with functions.

The problem is that there’s no way to forbid using mixins as functions. It is possible to use one as the other and they (and me 😃 get to use that ability. So de facto it’s only a matter of syntactic sugar and verbosity:

.sum(@a, @b) {
    @-: (@a + @b);
}

usage {
    width: @-;.sum(20px, 33px);
}

Using same “function” twice in the “same scope”:

// short (since 1.6.2):
usage {
    & {width:  @-;.sum(55px, 77px)}
    & {height: @-;.sum(11px, 99px)}
}

// oldschool (since 1.4.x):
usage {
    .-() {width:  @-;.sum(20px, 33px)}
    .-() {height: @-;.sum(40px, 42px)}
    .-();
}

Is there a reason to invent some new “Less function declaration/definition” syntax (different from a mixin definition syntax) only to not allow to use width: .sum(20px, 33px); directly?

Read more comments on GitHub >

github_iconTop Results From Across the Web

mixin and @include - Sass
keywords() function takes an argument list and returns any extra keywords that were passed to the mixin as a map from argument names...
Read more >
LESS - Mixin & return values - Tutorialspoint
LESS - Mixin & return values, Mixins are similar to functions and the variables that are defined in a mixin will behave as...
Read more >
Sass/scss 'mixin as a function' to return a string with parameters?
I have a Mixin in LESS with parameters that returns a string. I use this mixin calculate responsive properties like margins, paddings and ......
Read more >
How do I change the return value using a Mixin?
I have a method that i want to change that looks like this: public boolean checkSomething(int value) { return (value / other value) ......
Read more >
Sass/SCSS Mixins, Functions & @includes Tutorial - KoderHQ
To return a value from a function, we use the @return rule, followed by the value we want to return. Syntax: SCSS function....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found