节俭节点JavaScript名称空间
我似乎遇到节点/节俭名称空间冲突。
Foo.thrift ... struct Error { 1: i32 code, 2: string message } ...
通过thrift --gen js:node Foo.thrift
生成以下文件thrift --gen js:node Foo.thrift
(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"));
在callback中,它显示了我有一个包含code
和message
的对象,与一个包含“消息”的普通旧JS错误,即使我没有要求FooTypes.Error
。
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Error
有没有人碰到过这个? 我如何引用普通的JS错误?
谢谢
您缺less名称空间声明。 尝试这个:
# Foo.thrift file content namespace js Foo ... struct Error { 1: i32 code, 2: string message } ...
那么你的节俭对象将是Foo.Error
。