因爲sass的做者是rubyer,所以它的類型與JS有點不同,但同樣能夠類推。css
@charset "utf-8";//必須設置了這個才能編譯有中文的註釋 $gray: #333;//顏色 $number: 12;//數字 $boolean: true; $array:(); $string:"string"; $string2: 'string'; $null:null; $map: ( aa:1, bb:2 ); @mixin box-shadow($shadows) { -moz-box-shadow: $shadows; -webkit-box-shadow: $shadows; box-shadow: $shadows; } .aaa { content: type-of($gray); } .bbb { content: type-of($number); } .ccc{ content: type-of($boolean); } .ddd { content: type-of($array); } .eee { content: type-of($string); } .fff { content: type-of($string2); } .ggg { content: type-of($null); } .hhh { content: type-of(type-of); } .iii { content: type-of($map); } .kkk { content: type-of(box-shadow); } //-------------------------------------- .aaa { content: color; } .bbb { content: number; } .ccc { content: bool; } .ddd { content: list; } .eee { content: string; } .fff { content: string; } .ggg { content: null; } .hhh { content: string; } .iii { content: map; } .kkk { content: string; }
能夠看到sass的類型有null, string, bool, number, list, map, color這幾種類型,若是直接拿內置函數的名字或@mixin函數放進type-of裏,都是獲得字符串。web
但type-of不能斷定@function函數與@mixin函數,這時就須要用到function_exists, mixin_exists這兩個方法了,但我以爲它們的名字起得很差,不是中槓線連在一塊兒!sass
@charset "utf-8";//必須設置了這個才能編譯有中文的註釋 @mixin box-shadow($shadows) { -moz-box-shadow: $shadows; -webkit-box-shadow: $shadows; box-shadow: $shadows; } .testvar1{ content: function_exists("type-of"); } .testvar2{ content: mixin_exists("box-shadow"); } //-------------------------------------- .testvar1 { content: true; } .testvar2 { content: true; }
有了類型斷定,咱們就能夠玩參數泛型化了。ruby