Css 在SASS中通过引用传递函数或混合

Css 在SASS中通过引用传递函数或混合,css,sass,Css,Sass,有没有办法通过引用将函数或mixin传递给SASS中的另一个函数或mixin,然后调用引用的函数或mixin 例如: @function foo($value) { @return $value; } @mixin bob($fn: null) { a { b: $fn(c); // is there a way to call a referenced function here? } } @include bob(foo); // is there

有没有办法通过引用将函数或mixin传递给SASS中的另一个函数或mixin,然后调用引用的函数或mixin

例如:

@function foo($value) {
    @return $value;
}

@mixin bob($fn: null) {
    a {
        b: $fn(c); // is there a way to call a referenced function here?
    }
}

@include bob(foo); // is there any way I can pass the function "foo" here?

函数和mixin在Sass中不是一流的,这意味着您不能像对待变量那样将它们作为参数传递

Sass 3.2及更高版本 您可以使用
@content
指令(Sass 3.2+)获得最接近的结果

唯一需要注意的是,
@content
无法看到混音器中的内容。换句话说,如果
c
仅在
bob
mixin中定义,那么它基本上不存在,因为它不在范围内考虑

Sass 3.3及更新版本 从3.3开始,您可以使用
call()
函数,但它仅用于函数,不用于混合。这需要传递包含函数名的字符串作为第一个参数

@function foo($value) {
    @return $value;
}

@mixin bob($fn: null) {
    a {
        b: call($fn, c);
    }
}

@include bob('foo');

函数和mixin在Sass中不是一流的,这意味着您不能像对待变量那样将它们作为参数传递

Sass 3.2及更高版本 您可以使用
@content
指令(Sass 3.2+)获得最接近的结果

唯一需要注意的是,
@content
无法看到混音器中的内容。换句话说,如果
c
仅在
bob
mixin中定义,那么它基本上不存在,因为它不在范围内考虑

Sass 3.3及更新版本 从3.3开始,您可以使用
call()
函数,但它仅用于函数,不用于混合。这需要传递包含函数名的字符串作为第一个参数

@function foo($value) {
    @return $value;
}

@mixin bob($fn: null) {
    a {
        b: call($fn, c);
    }
}

@include bob('foo');