我有以下代碼。現在,當構造函數被調用時,對象被創建。現在,在更新字段時,他們正在像這樣更新。請注意,我無法修改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();
});