2013-04-04 80 views
2

我似乎遇到節點/節儉名稱空間衝突。節儉節點JavaScript名稱空間

Foo.thrift 
... 
struct Error { 
    1: i32 code, 
    2: string message 
} 
... 

經由thrift --gen js:node Foo.thrift生成以下文件(節儉v0.9.0)

Foo_types.js 
... 
Error = module.exports.Error = function(args) { 
    this.code = null; 
    this.message = null; 
    if (args) { 
    if (args.code !== undefined) { 
     this.code = args.code; 
    } 
    if (args.message !== undefined) { 
     this.message = args.message; 
    } 
    } 
}; 
Error.prototype = {}; 
Error.prototype.read = function(input) { 
... 

我包括在節點的模塊

var FooTypes = require('./../gen-nodejs/Foo_types') 

我似乎碰上與JavaScript的一個命名空間衝突錯誤對象

callback(new Error("Couldn't find profile")); 

在回調中,它顯示我有一個對象codemessage與包含「消息」的普通舊JS錯誤,即使我沒有要求FooTypes.Error

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Error

有其他人遇到了這個?我如何引用普通的JS錯誤?

謝謝

回答

2

您缺少名稱空間聲明。試試這個:

# Foo.thrift file content 
namespace js Foo 
... 
struct Error { 
    1: i32 code, 
    2: string message 
} 
... 

然後你的節儉物體是Foo.Error