判断参数是否是其中之一

  • 正常写法 ```javascript function oneOf(value, validList) { for (let i = 0; i < validList.length; i++) { if (value === validList[i]) {
    1. return true;
    } } return false; }

validator(value) { return oneOf(value, [“small”, “large”, “default”]); },

  1. - 高级
  2. ```javascript
  3. function oneOf(value, validList) {
  4. return validList.some((item) => {
  5. return item === value;
  6. });
  7. }