我目前有一个非常简单的文件:
var {
Object,
File,
Relation,
Cloud,
} = Parse
final class Job extends Object {
constructor(params) {
super("Job")
this.descriptionText = params.descriptionText
this.completed = false
this.currentBids = this.relation("currentBids")
this.bidCount = 0
this.acceptedBid = false
const imageFile = new File("imageFile", params.imageBytes);
imageFile.save()
this.imageFile = imageFile
this.jobTitle = params.jobTitle
this.jobCategory = params.jobCategory
this.createdBy = params.user
}
}
Cloud.define("createJob", function(request, response) {
const job = Job(request.params);
job.save().then(function() {
response.success()
}, function(error) {
response.error("Error saving job")
})
})
来自Parse Docs:
如果您已在代码库中使用ES6,那么这是个好消息!从1.6.0版开始,JavaScript SDK与ES6类兼容。您可以使用extends关键字
将Parse.Object子类化
然而,当我运行parse deploy
时,我得到了:
Error: Uncaught SyntaxError: Unexpected token { in Job.js:1 at main.js:1:1
我对JavaScript很新,所以上面的代码可能是错误的。但我不明白为什么它会从解构语法开始就出错。