String.prototype.includes

if (!String.prototype.includes) {
  String.prototype.includes = function(search, start) {
    'use strict';
    if (typeof start !== 'number') {
      start = 0;
    }
    
    if (start + search.length > this.length) {
      return false;
    } else {
      return this.indexOf(search, start) !== -1;
    }
  };
}
posted @ 2016-04-28 08:12  shidengyun  阅读(182)  评论(0编辑  收藏  举报