问题描述
对于某些"提取",操作我试图在不使用传播运算符的情况下获得以下代码段工作,因为IE 11不了解传播运算符.
For some "extraction" operation I am trying to get the following snippet work, without using the spread operator, because IE 11 doesn't knows about spread operators.
可在Chrome中运行,但不能在IE 11中运行:
html_col_width =[{"targets":0, "width":50}, {"targets":1, "width":100},{"targets":2, "width":442}]
... some other code
order: [
[response.order_by_column, response.order_by]
],
columnDefs: [
...html_col_width,
{other: stuff},
{other: stuff}
})
请参见列Defs:... html_col_width
在没有传播运算符的情况下如何实现以下目标:
How can I achieve the following without the spread operator:
columnDefs: [
{"targets":0, "width":50},
{"targets":1, "width":100},
{"targets":2, "width":442},
{other: stuff},
{other: stuff}
})
我已经阅读并尝试了以下操作,但是如果对象数组包含2个键,则此操作不起作用:中的Spread Operator等效.提供的链接上的内容是关于合并的不同对象,这使问题大为不同.
I have read and tried the following, but this is not working if the array of objects contains 2 keys: Spread Operator equivalent in IE - Javascript. The content at the provided link is about merging different objects, which makes the question rather different.
推荐答案
您正在使用的被称为数组解构": https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
What you are using is called "Array Destructuring": https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
正如您所说,它在IE中不起作用,这是因为它是ES6的一部分,并且(永远不会)在IE 11中不受支持.
As you said, it doesn´t work in IE, and that is because it´s part of ES6 and that is not (and never will) supported in IE 11.
解决该问题的一种方法是使用Babel这样的编译器.
One option to solve it is using transpilers like Babel.
其他选项是定义自己的功能:
Other option, is to define your own function:
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var html_col_width = [{ "targets": 0, "width": 50 }, { "targets": 1, "width": 100 }, { "targets": 2, "width": 442 }];
var columnDefs = __spreadArrays(html_col_width, [{ other: 'stuff' }, { other: 'stuff' }]);
这篇关于如何在IE 11中实现传播算子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!