功能

兼容性(参数类型):
Dart·Sass(Dart Sass)
LibSass
从  3.5.0开始
rubySass
从  3.5.0开始

在较旧的LibSass和Ruby Sass版本中,该call()函数采用了代表函数名称的字符串。为了准备一个新的模块系统(功能不再是全局的),所以更改了它的功能值,以准备一个新的模块系统,因此给定的名称可能并不总是引用相同的功能。

将字符串传递给call()所有实现仍然可以使用,但已弃用,并且在以后的版本中将不允许使用。

函数也可以是值!您不能直接将函数编写为值,但是可以将函数名称传递给[ meta.get-function()function] []以将其作为值。一旦有了函数值,就可以将其传递给meta.call()函数来调用它。这对于编写调用其他函数的高阶函数很有用。

SCSS  语法

@use "sass:list";
@use "sass:meta";
@use "sass:string";

/// Return a copy of $list with all elements for which $condition returns `true`
/// removed.
@function remove-where($list, $condition) {
  $new-list: ();
  $separator: list.separator($list);
  @each $element in $list {
    @if not meta.call($condition, $element) {
      $new-list: list.append($new-list, $element, $separator: $separator);
    }
  }
  @return $new-list;
}

$fonts: Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif;

content {
  @function contains-helvetica($string) {
    @return string.index($string, "Helvetica");
  }
  font-family: remove-where($fonts, meta.get-function("contains-helvetica"));
}

Sass语法

@use "sass:list"
@use "sass:meta"
@use "sass:string"

/// Return a copy of $list with all elements for which $condition returns `true`
/// removed.
@function remove-where($list, $condition)
  $new-list: ()
  $separator: list.separator($list)
  @each $element in $list
    @if not meta.call($condition, $element)
      $new-list: list.append($new-list, $element, $separator: $separator)


  @return $new-list


$fonts: Tahoma, Geneva, "Helvetica Neue", Helvetica, Arial, sans-serif

content
  @function contains-helvetica($string)
    @return string.index($string, "Helvetica")

  font-family: remove-where($fonts, meta.get-function("contains-helvetica"))

CSS  输出

content {
  font-family: Tahoma, Geneva, Arial, sans-serif;
}