Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why SASS doesnt have local variables? [closed]

Just switched from LESS and found that in SASS all variables in global. And so to define special variable for particular block I need to write something like $words-that-describe-particular-block-padding: 10px;.

In all reviews authors rendered SASS as more advanced than LESS because of its feature-richness, but actually lack of such simple thing as namespacing kills all experience with it.

Why that design decision was made?
Am I wrong and global-only variables are better by the reason that I am missing?

upd:
SASS:

$var: 1px;
#id1 {
$var: 2px;
width: $var;
}
#id2 {
width: $var;
}

LESS:

@var: 1px;
#id1 {
@var: 2px;
width: @var;
}
#id2 {
width: @var;
}

Try the examples with this online compilers:

  • http://sass-lang.com/try.html
  • http://less2css.org/
like image 501
Gill Bates Avatar asked Dec 06 '22 05:12

Gill Bates


1 Answers

That's not exactly true. If you run the following code:

.header {
   $color: #000;
   background: $color;
}
.footer {
   background: $color;
}

You will get

Sass Error: Undefined variable: "$color".

So, the color variable is not global at all. It is available only in the context of its definition.

However, SASS or LESS has a lot of limitations. If you are not happy with the things which they offer I'll suggest to check this.

like image 99
Krasimir Avatar answered Dec 25 '22 02:12

Krasimir