2013-02-13 24 views
1

什麼是刪除用於?我以前沒有看到這樣的語法,任何人都可以幫助我? 的代碼片段是非常容易的,它使用的node.js,貓鼬,MongoDB的node.js「刪除」的奇怪語法

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); 
} 

回答

2

delete在JavaScript removes the property from the object

var game = { 
    id: 1 
} 

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

delete game.id 

console.log(game); // undefined 
+0

非常感謝,對不起,我的無知javascript – clevertension 2013-02-13 11:36:53

+0

沒問題,這就是本網站的目的!你的問題是有效的,值得問,請不要道歉努力改善自己! – 2013-02-13 11:41:04

1

它用於從對象中移除屬性。所以在這種情況下,它會從更新中刪除_id屬性