我有以下代码。现在,当构造函数被调用时,对象被创建。现在,在更新字段时,他们正在像这样更新。请注意,我无法修改Comment()
,因为它是由猫鼬创建的。Javascript中的对象声明
var newComment = new Comment();
newComment.content = req.body.content;
newComment.user.id = req.body.id;
newComment.user.name = req.body.name;
newComment.user.profilePicture = req.user.profilePicture;
newComment.votes.up = [];
newComment.votes.down = [];
newComment.comments = [];
newComment.timestamp = Date.now();
有没有办法做一些事情来更新这样的对象:
newComment.SOMEFUNCTION({
content = req.body.content;
user.id = req.body.id;
user.name = req.body.name;
user.profilePicture = req.user.profilePicture;
votes.up = [];
votes.down = [];
comments = [];
timestamp = Date.now();
});