我看到有这样的示例:
// 1.使用常量指定固定的属性值。
color('red');
// 2.使用数组进行数据映射。
color('type', ['red', 'blue']);
// 3.使用回调函数进行数据映射。
color('type', function(type) {
if(type == 'type1') {
return 'red';
}
return 'blue';
});
我没有看明白第3个示例,第2个可以认为是配置渐变色,但是第三个指定回调函数有什么用呢?是否是第一个参数type
如果传递为type1
那么就返回red
颜色?如果是为何不直接就使用第一个示例,何必画蛇添足?
因为有时候你写代码的时候不知道该用什么颜色,需要结合运行时的状态,通过计算得到。