可以在ES2015中将方法缩写与脂肪箭合并吗? [英] Possible to combine method-shorthand with fat-arrows in ES2015?

查看:84
本文介绍了可以在ES2015中将方法缩写与脂肪箭合并吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道ES2015有方法简写:

  let obj = {
myMethod (){
alert(STUFF!);
}
};

我也知道它有胖箭头支持:

  let myMethod =()=>警报( STUFF!); 

但是可以将两个< STRONG>?这似乎不起作用:

  let obj = {
myMethod()= > alert(STUFF!)
};

最接近的是这个,但不使用方法简写:

  let obj = {
myMethod:()= > alert(STUFF!)
};

如果目前不支持,这是为将来的修订计划吗?

解决方案


但是可以组合这两个?


否。


如果目前不支持,这是未来修订的计划?


不,这太微不足道了。您可以在示例中看到,只需一个冒号就可以实现,而没有别的可能会有所不同。


个人使用情况对我有意义,我很惊讶地发现他们不合作。


您必须将方法定义视为函数定义(函数声明,函数表达式,箭头函数,方法)的第四种形式。因此,组合它们是没有意义的。


I know ES2015 has method shorthand:

let obj = {
  myMethod() {
    alert("STUFF!");
  }
};

I also know it has fat arrow support:

let myMethod = () => alert("STUFF!");

But is it possible to combine the two? This does not seem to work:

let obj = {
  myMethod() => alert("STUFF!")
};

The closest I could get is this, but it doesn't use the method-shorthand:

let obj = {
  myMethod: () => alert("STUFF!")
};

If not currently supported, is this something planned for future revisions?

解决方案

But is it possible to combine the two?

No.

If not currently supported, is this something planned for future revisions?

No, it is too insignificant. As you can see in your example, it can be achieved with just a single colon, and nothing else would be different.

The individual use cases make sense to me and I was surprised to find that they do not work together.

You have to consider method definitions as a fourth form of a function definition (function declaration, function expression, arrow functions, methods). As such, it doesn't make sense to "combine" them.

这篇关于可以在ES2015中将方法缩写与脂肪箭合并吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆