Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About Variables / Default Variables #515

Open
HalfLegend opened this issue Jun 23, 2019 · 1 comment
Open

About Variables / Default Variables #515

HalfLegend opened this issue Jun 23, 2019 · 1 comment

Comments

@HalfLegend
Copy link

HalfLegend commented Jun 23, 2019

http://lesscss.cn/features/#variables-feature-default-variables
It writes:
We sometimes get requests for default variables - an ability to set a variable only if it is not already set.

This feature is not required because you can easily override a variable by putting the definition afterwards.

For instance:

// library
@base-color: green;
@dark-color: darken(@base-color, 10%);

// use of library
@import "library.less";
@base-color: red;

This works fine because of Lazy Loading - base-color is overridden and dark-color is a dark red.


I don't think the behavior in the example meets the instruction, because the @base-color is already set to green, it shouldn't be reset to red.

So I think the instruction should be:
" We sometimes get requests for default variables - an ability to set a variable only if it is not already set.

This feature is conflicted with 'overriding a variable by putting the definition afterwards', so we couldn't implement the behavior of default variables."

@seven-phases-max
Copy link
Member

so we couldn't implement the behavior of default variables."

Well, we could. It just would make no sense in Less. For more details on this see less/less.js#1706

I don't think the behavior in the example meets the instruction, because the @base-color is already set to green, it shouldn't be reset to red.

I'm not sure I understand what you actually mean with this. Could you elaborate?
Note that Less overriding is not a replacement for Sass !default. It's a different paradigm to achieve a desired behavior for similar use-cases (in other words: !default is a kludge required in Sass to achieve the things naturally existing in Less by design. Nothing more than this).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants