2012-07-29 65 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模型就是这种情况。