doukun8670 2017-01-22 17:42
浏览 32
已采纳

Javascript关联数组速记在IE中不起作用

I'm using ajax to post to the server, with the following code:

$.post( "/api/server_login.php", { variable_1, variable_2 }, function( json ) {...

Where the array in the middle is short-form for:

$.post( "/api/server_login.php", { variable_1:variable_1, variable_2:variable_2 }, function( json ) {...

In other words, using the variable name as the key AND the variable contents as the value.

This short-form works in all browsers except Internet Explorer.

Did I make this short-form up, with it just happening to be working in all the other browsers? Or is this something I can fix in Internet Explorer somehow?

Tried looking for resources on this but couldn't find anyone else using this short-hand for associative arrays in Javascript!

  • 写回答

2条回答 默认 最新

  • dongshadu4498 2017-01-22 17:51
    关注

    This is a new feature in ES6/ES2015, where you can use a variable name for both the key and value of an object. You can read more about it here: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Object_initializer

    Notice the browser compatibility at the bottom of the page and that IE doesn't have support for 'Shorthand property names'.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向