`caDelete` 方法报错?
TypeError: Cannot read property 'canDelete' of undefined 是什么原因呢?
reply.can_delete = this.canDelete(user, reply)
.
.
.
canDelete(user, reply) {
if (!user) {
return false
}
return (reply.user_id === user.id)
}
关于 LearnKu
不要
canDelete方法暂时解决了问题 :joy:
Cannot read property 'canDelete' of undefined为什么 this 会是 undefined,去看一下github 上的项目源码,对比一下吧
@liyu001989 这应该是ES5 es6的差异吗。。我是后端 没有阅读这些规范
上方是教程的(严格的说应该是教程之前章节写的和本章不同),下方是Github的。。
https://stackoverflow.com/questions/455980...
@JeffLi
(reply) => {}等同于function (reply) {}ES6 箭头函数了解一下~@TYu 我知道啊,但是我前端不熟悉,我只知道,改成这样就不报错了。。
@JeffLi 哈 前段我也不熟 只是稍微了解 - -