简体   繁体   English

如何在里面使用es6函数params?

[英]How to use es6 functions params inside it?

在这种情况下是否可以使用 es6 函数参数?

 func = param => this.transform(this.targets.param)

Sure.当然。 These are just normal functions.这些只是正常的功能。 The parameters of the functions are available in the scope of the function definition.函数的parameters在函数定义的范围内可用。

 func = param => this.transform(param)

equivalent to相当于

func = param => {
     return this.transform(param);
 }

I assume you have a problem with closures;我假设你有闭包的问题; that is that the "this" does not reference what you would expect ...那就是“这个”没有引用你所期望的......

Can you try the following:您可以尝试以下操作:

func = (param, that) => {
     return that.transform(param);
 }

Then call the function with the right context:然后使用正确的上下文调用函数:

func(param, this);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM