includes() not working in all browsers

前端 未结 6 1562
不思量自难忘°
不思量自难忘° 2020-11-27 17:24

right here is a block of my code. It works perfect in fireFox and Chrome. But not in IE. I get the error \"Object doesn\'t support property or method \'includes\'

6条回答
  •  被撕碎了的回忆
    2020-11-27 18:04

    IE11 does implement String.prototype.includes so why not using the official Polyfill?

    Source: polyfill source

      if (!String.prototype.includes) {
        String.prototype.includes = function(search, start) {
          if (typeof start !== 'number') {
            start = 0;
          }
    
          if (start + search.length > this.length) {
            return false;
          } else {
            return this.indexOf(search, start) !== -1;
          }
        };
      }
    

提交回复
热议问题