He estado trabajando en un proyecto y desarrollando un marco de JavaScript. El código original tiene unas 700 líneas, así que solo pegué esta línea. El método include no funciona en Internet Explorer. ¿Hay alguna solución para esto?
var row_cells = tbl_row.match(/<td[\s\S]*?<\/td>/g); row.Cells = new Array(); if (onRowBindFuncText != null) { /*Fonksyon tanımlanmaışsa daha hızlı çalış*/ var cellCount = 0; for (i = 0; i < row_cells.length; i++) { var cell = new Cell(); $.each(this, function (k, v) { if ((row_cells[i]+"").includes("#Eval(" + k + ")")) { cell.Keys.push(new Key(k,v));
... El código continúa
Debido a que no es compatible con IE, tampoco es compatible con Opera ( consulte la tabla de compatibilidad ), pero puede usar el polyfill sugerido:
polirelleno
Este método se agregó a la especificación ECMAScript 2015 y es posible que aún no esté disponible en todas las implementaciones de JavaScript. Sin embargo, puede rellenar fácilmente este método:
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; } }; }
@Infer-on mostró una gran respuesta, pero tiene un problema en una situación específica. Si usa el bucle for-in, devolverá incluye la función "incluye" que agregó.
Aquí hay otro pollyfill.
if (!Array.prototype.includes) { Object.defineProperty(Array.prototype, "includes", { enumerable: false, value: function(obj) { var newArr = this.filter(function(el) { return el == obj; }); return newArr.length > 0; } }); }
Simplemente podría usar .search() > -1 que se comporta exactamente de la misma manera. http://www.w3schools.com/jsref/jsref_search.asp
if ((row_cells[i]+"").search("#Eval(" + k + ")") > -1) {