Can Sass evaluate strings that contain mathematical expressions?

后端 未结 1 1868
感情败类
感情败类 2020-12-20 02:16

I\'m trying to create a function which will output a list of numbers based on an expression given to it.

Does anyone know how I can pass an expression through a func

相关标签:
1条回答
  • 2020-12-20 02:35

    No. Sass does not have an eval function. The closest you can get is by using the call function.

    @function my-expression($x, $y) {
      @return $x * $y + 2;
    }
    
    @function patt($expression, $b: 10) {
        $result: ();
        @for $i from 1 through 10 {
            $result: append($result, call($expression, $i, $b));
        }
        @return $result;
    }
    
    $list: patt('my-expression'); // 12 22 32 42 52 62 72 82 92 102
    
    0 讨论(0)
提交回复
热议问题