这段代码
let test = {
method () {
// ...
}
}
会被转译为
"use strict";
var test = {
method: function method() {
// ...
}
};
那么 function method () 有方法调用吗?如果没有,何不转译成这样:
"use strict";
var test = {
method: function () {
// ...
}
};
严格模式下,就不要说什么 callee 了
1
messense Aug 26, 2016
匿名函数不方便 debug
|
2
szharrydev Aug 26, 2016
给匿名函数加了个方法名而已 。。。 调用还是一样 。。。
|
3
yyfearth Aug 26, 2016
只有这样 function 的 name 属性才会是 method
|
4
adeweb Aug 26, 2016
3 楼正解。
|
5
sunjourney OP @yyfearth 怎么拿到这个 function name ? test.method.name 用我的写法也是 method
|
6
TomIsion Aug 26, 2016
Mark 下
|
7
morethansean Aug 26, 2016 @sunjourney https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
里面提到实现了 ES6 functions 的浏览器能推断出 function name. 你的测试环境是最新的 Chrome 吧? |
8
sunjourney OP @morethansean 感谢,正解!!
|
9
sinalvee Aug 26, 2016
|