
这段代码
let test = { method () { // ... } } 会被转译为
"use strict"; var test = { method: function method() { // ... } }; 那么 function method () 有方法调用吗?如果没有,何不转译成这样:
"use strict"; var test = { method: function () { // ... } }; 严格模式下,就不要说什么 callee 了
1 messense 2016-08-26 11:44:01 +08:00 匿名函数不方便 debug |
2 szharrydev 2016-08-26 11:45:28 +08:00 给匿名函数加了个方法名而已 。。。 调用还是一样 。。。 |
3 yyfearth 2016-08-26 12:29:07 +08:00 只有这样 function 的 name 属性才会是 method |
4 adeweb 2016-08-26 12:39:43 +08:00 3 楼正解。 |
5 sunjourney OP @yyfearth 怎么拿到这个 function name ? test.method.name 用我的写法也是 method |
6 TomIsion 2016-08-26 14:22:11 +08:00 Mark 下 |
@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 2016-08-26 15:34:50 +08:00 |