[英]Converting an es6 arrow function to es5 manually?
How do we convert the arrow function below to es5 manually?我们如何手动将下面的箭头函数转换为es5?
e => varName = e.target.value
My attempt:我的尝试:
function(e) {
varName = e.target.value
return varName
}
Am I right?我对吗?
What about this below?下面这个呢?
varName = function(e) {
return e.target.value
}
Both of them are extremely similar and perform nearly the same task, however the ES6 function implicitly creates a global variable named varName
and assigns it a value, and neither of the ES5 functions do that.它们非常相似并且执行几乎相同的任务,但是 ES6 函数隐式创建了一个名为varName
的全局变量并为其赋值,而 ES5 函数都没有这样做。 This one is pretty much exactly the same:这个几乎完全一样:
function(e) {
return varName = e.target.value;
}
Or:或者:
function(e) {
varName = e.target.value;
return varName;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.