手写笔如何处理范围的变量?

--

1- 所有变量都是全局变量吗?

$foo = red // is $foo global?

2- commonJS module类似,是否有等效的exports/require
$foo = @import 'foo'

body { color: $foo }

3- 在CSS块中声明的变量(也许使用mixins)如何:
$foo = green

bar()
  $foo = yellow // is it the same $foo ?
  $baz = blue.  // local or implied global?

ul {

  background: $foo // green or yellow? red?

  $foo = red

  li {

    $foo = pink

  }

  color: $foo // pink?

  bar() // what about $foo now?

}

--

希望对此有任何澄清或说明...

谢谢

最佳答案

如果您稍微重述问题的第3部分:

$foo = green
p('global: $foo is ' $foo)

bar()
  $foo = yellow
  p('In bar(): $foo is ' $foo)
  $baz = blue

p('$baz outside of bar() is ' $baz)

ul {

  background: $foo
  p('In ul: $foo is ' $foo)

  $foo = red
  p('In ul: now $foo is ' $foo)

  li {

    $foo = pink
    p('In ul li: $foo is ' $foo)

  }

  color: $foo // pink?
  p('Back in ul: now $foo is ' $foo)

  bar()
  p('what about $foo now? ' $foo)
}

然后手写笔将回答:
$ stylus test.styl
inspect: 'global: $foo is ' (#008000)
inspect: '$baz outside of bar() is ' $baz
inspect: 'In ul: $foo is ' (#008000)
inspect: 'In ul: now $foo is ' (#f00)
inspect: 'In ul li: $foo is ' (#ffc0cb)
inspect: 'Back in ul: now $foo is ' (#f00)
inspect: 'In bar(): $foo is ' (#ff0)
inspect: 'what about $foo now? ' (#f00)
  compiled test.css

关于module - 手写笔中的可变范围,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9591171/

10-10 19:08