10

スタイラスは変数スコープをどのように処理しますか?

-

1-すべての変数はグローバルですか?

$foo = red // is $foo global?

2- commonJSモジュールと同様に、exports/require同等のものはありますか?

$foo = @import 'foo'

body { color: $foo }

3-おそらくミックスインを使用してCSSブロックで宣言された変数はどうですか?

$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?

}

-

これに関する説明やドキュメントをいただければ幸いです...

ありがとうございました

4

1 に答える 1

10

質問のパート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
于 2012-08-17T01:02:22.737 に答える