【发布时间】:2011-11-14 02:08:05
【问题描述】:
也许我不像我想的那样理解 javascript/coffee 脚本,但是当我这样做时:
that.thing = thing
that.thing.title = "some title"
console.log(that.thing.title)
console.log(JSON.stringify(that.thing)
我得到输出:
一些标题
{"creation_date":"2011-09-09T00:40:03.742Z","_id":"4e6960638ec80519a0000013"}
问题是我在执行 stringify 时似乎丢失了 title 属性(后来当函数存在时,我似乎遇到了其他有趣的问题,我认为这些问题与 'that' 和 this 嵌套在多个 fxn 中有关电话)。
(我现在不得不做一个丑陋的解决方案,我这样做了。thing = {} 来解决我的问题。我之前必须解决的其他问题包括 node.js + async + mongoose.find,这都是在 async .findEach)
当我这样做时
console.log(that.thing.toJSON)
我明白了:
function () { return this.toObject(); }
谢谢。
【问题讨论】:
-
你确定
that.thing不是一个可怕的getter/setter 吗?
标签: json node.js asynchronous mongoose