我开始学习ES6 &写了这个代码:为什么这段代码总是返回undefined?
let dog = {
s:'Woff',
talk:()=>{console.log(this.s)}
};
dog.talk();
let x = dog.talk;
x();
x.bind(dog)();
为什么它总是返回undefined,而不是 'WOFF'?我认为只有1行返回undefined,但我们有3个未定义。
console.log返回未定义。 –
1.您没有任何'return'语句,并且2.您的console.log(console.log(...))' – crashmstr
@JaredSmith刚刚检查过文档,并且因为他有'{}'' (块体)他需要一个回报,据我所知:[箭头函数](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) – crashmstr