olivernn / augment.js

Modern JavaScript in your IE
https://olivernn.github.io/augment.js/
MIT License
431 stars 31 forks source link

Can we add string.include method? #19

Open hk-skit opened 8 years ago

hk-skit commented 8 years ago

As described here Mozila doc, there's a method string.includes to check whether a string contains searchString or not.


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;
    }
  };
}

We should also add this in augment.js

plugn commented 8 years ago

It is possible to use String.prototype.indexOf() instead: str.indexOf(searchValue[, fromIndex]) with the same effect

hk-skit commented 8 years ago

Yeah we can achieve the same with it but the thing is that every time we need to check whether the index is not equals -1.