1

删除是做什么用的?我以前没见过这样的语法,有人可以帮助我吗?代码片段非常简单,它用于 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);
}
4

2 回答 2

2

delete在 JavaScript中从对象中删除属性

var game = {
    id: 1
}

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

delete game.id

console.log(game);  // undefined
于 2013-02-13T11:22:32.120 回答
1

它用于从对象中删除属性。所以在这种情况下,它会从更新中删除 _id 属性

于 2013-02-13T11:23:51.390 回答