1 2 3 4 5 6 7 8 9 10 11 | var person = { get firstName(){ return "Nicholas" }, sayName: function (){ console.log( this .name); } } console.log(person.sayName.name); //"sayName" console.log(person.firstName.name); //并不是书上所说的"get firstName",而是"undefined" |
这是《深入理解ES6》53页的代码问题,不明白为什么和书上的输出不一样。如果我想获取person.firstName.name,那要怎么获取?