gpt4 book ai didi

node.js "delete"的奇怪语法

转载 作者:太空宇宙 更新时间:2023-11-03 23:10:26 25 4
gpt4 key购买 nike

删除有什么用?我以前没有见过这样的语法,有人可以帮助我吗?代码片段非常简单,使用了node.js、mongoose、mongodb

function _update(game, callback) {
if (!game) {
callback(new Error("Game must be provided."));
return;
}
if (!game.gameId) {
callback(new Error("Game id should be provided"));
return;
}

var updates = (game instanceof Game) ? game.toObject() : game;
delete updates._id;
updates.modifiedDate = new Date();

Game.findOneAndUpdate({"_id": game.id, "deleted" : {"$ne": true}}, updates, callback);
}

最佳答案

JavaScript 中的

删除 removes the property from the object .

var game = {
id: 1
}

console.log(game); // Object {id: 1}

delete game.id

console.log(game); // undefined

关于node.js "delete"的奇怪语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14852329/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com