Tag: ecmascript 6

如何从asynchronous调用返回响应?

我有一个函数foo ,这使得一个Ajax请求。 我怎样才能返回foo的回应? 我尝试从successcallback中返回值,并将响应分配给函数内部的局部variables,并返回该variables,但是没有一个方法实际返回响应。 function foo() { var result; $.ajax({ url: '…', success: function(response) { result = response; // return response; // <- I tried that one as well } }); return result; } var result = foo(); // It always ends up being `undefined`.

这个对象方法定义如何在没有“function”关键字的情况下工作?

我意外地发现了这个关键字的function 。 通常在下面的模块foobar方法将被宣布为foobar: function(arg1) ,但有趣的是,以下工作,至少在一些浏览器,如Chrome版本44.0.2403.157米,但它在IE 11.0.9600.17959 这怎么可能在任何浏览器中运行呢? 这是一些新的ES6功能? var module = { foobar(arg1) { alert(arg1); } }; module.foobar("Hello World");

将选项传递给ES6模块导入

是否有可能将选项传递给ES6进口? 你如何翻译这个: var x = require('module')(someoptions); 到ES6?

ES6是否为对象属性引入了明确定义的枚举顺序?

ES6是否为对象属性引入了明确定义的枚举顺序? var o = { '1': 1, 'a': 2, 'b': 3 } Object.keys(o); // ["1", "a", "b"] – is this ordering guaranteed by ES6? for(let k in o) { console.log(k); } // 1 2 3 – is this ordering guaranteed by ES6?