2012-07-29 591 views
1

我遇到了一些顯而易見的問題。我似乎無法刪除節點中的對象的屬性。這是咖啡文字,但我認爲這不相關。無法刪除行爲

console.log doc 
delete doc.password 
console.log doc 

返回:

{ firstname: 'Andrew', 
    lastname: 'Plummer', 
    email: '[email protected]', 
    password: 'blahblah', 
    _id: 5014c0a6af36bdaf03000001, 
    comments: [], 
    posts: [] } 

{ firstname: 'Andrew', 
    lastname: 'Plummer', 
    email: '[email protected]', 
    password: 'blahblah', 
    _id: 5014c0a6af36bdaf03000001, 
    comments: [], 
    posts: [] } 

對於一些看似那麼明顯其實我已經繞計算器搜索和Google搜索了約半小時。對不起,如果我仍然錯過了重複。

+0

你會顯示:'(function(){doc = {firstname:「Andrew」,lastname:「Plummer」,email:「andrew @ stackoverflow ...」,密碼:「blahblah」,_ id: 「5014c0a6af36bdaf03000001」,評論:[],帖子:[]},console.log(「刪除前:」+ doc.password),刪除doc.password,console.log(「刪除後:」+ doc.password)} )()' – 2012-07-29 07:07:35

+2

@Andrew,'password'屬性可能是通過調用[Object.defineProperty()]定義的(https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/defineProperty ),其中'可配置'描述符字段被省略(或明確設置爲'false')。在那種情況下,不能「刪除」該設計屬性。 – 2012-07-29 08:06:45

回答

0

Frédéric在評論中給出的答案(所以我不能將它標記爲true)是因爲我的對象禁用了刪除,所以我需要明確地將對象變成一個新對象。節點中的貓鼬ODM模型就是這種情況。