Sass 內省函式
Sass 內省函式
在構建樣式表時,內省函式很少使用。但是,如果某些地方不起作用,它們對於弄清楚發生了什麼非常有用——就像除錯函式一樣。
下表列出了 Sass 中的所有內省函式。
函式 | 描述 & 示例 |
---|---|
call(function, arguments...) | 使用引數呼叫函式,並返回結果。 |
content-exists() | 檢查當前 mixin 是否傳遞了 @content 塊。 |
feature-exists(feature) | 檢查當前 Sass 實現是否支援 feature。 示例 feature-exists("at-error"); 結果: true |
function-exists(functionname) | 檢查指定的函式是否存在。 示例 function-exists("nonsense") 結果: false |
get-function(functionname, css: false) | 返回指定的函式。如果 css 為 true,則返回一個純 CSS 函式。 |
global-variable-exists(variablename) | 檢查指定的全域性變數是否存在。 示例 variable-exists(a) 結果: true |
inspect(value) | 返回 value 的字串表示。 |
mixin-exists(mixinname) | 檢查指定的 mixin 是否存在。 示例 mixin-exists("important-text") 結果: true |
type-of(value) | 返回 value 的型別。可以是 number、string、color、list、map、bool、null、function、arglist。 示例 type-of(15px) 結果:number type-of(#ff0000) 結果:color |
unit(number) | 返回與數字關聯的單位。 示例 unit(15px) 結果:px |
unitless(number) | 檢查指定的數字是否有關聯的單位。 示例 unitless(15px) 結果: false unitless(15) 結果: true |
variable-exists(variablename) | 檢查指定的變數在當前作用域中是否存在。 示例 variable-exists(b) 結果: true |