小编Kri*_*ari的帖子

this 在异步对象方法中

我使用 babel-polyfill/babel-preset-es2017 创建了一个使用异步函数方法的对象,但是我遇到了以下问题this

let obj = () => {
    return {
        doAsync: async () => {
            let thing = await longProcess()
            return this.transform(thing)
        },

        transform: (thing) => {
            return psuedoCodeTransform(thing)
        }
    }
}

let instance = obj()
instance.doAsync()
// TypeError: cannot read property 'transform' of undefined`.
Run Code Online (Sandbox Code Playgroud)

这是否在 ES2017 中描述过,babel-polyfill/regeneratorRuntime 问题?

javascript this async-await babeljs ecmascript-2017

5
推荐指数
1
解决办法
4034
查看次数

在Javascript中,为什么空扩散阵列Infinity的最小值?

我正在使用生成器来创建对象,如下所示:

function* Thing() {
  var x = 0;
  while (x < 3) {
    var rules = [{arr: [1, 2, 3]}, {arr: [1]}, {arr: []}];
    yield {
      arrayMinimum: Math.min(...rules[x].arr)
    }
    x++
  }
}

var create = Thing();

console.log(create.next().value)
console.log(create.next().value)
console.log(create.next().value) // { arrayMinimum: Infinity } ???
Run Code Online (Sandbox Code Playgroud)

为什么Math.min(...[]) === Infinity

奖金混乱:Math.max(...[]) === -Infinity???

javascript arrays ecmascript-6

4
推荐指数
1
解决办法
1587
查看次数