如何在node.js中使用原型

我在nodejs上编写我的第一个模块。 我需要从谷歌cachingparsing我的网站。 post是桌子的地图。 当我尝试使用这个模块,我有这个错误:“types错误:不能设置未定义的属性”原型“如何解决这个错误?这是我的代码:

module.exports = function Post(documentDOM,options) { this.opts = $.extend({id:0,author_id:0},options); this.doc = documentDOM; this.post = { id: 0, name: '', alt_name: '', notice: '', content: '', author: '', author_id: 0, }; } module.exports.Post.prototype = { init: function() { this.post.id = this.opts.id; this.post.author_id = this.opts.author_id; }, content: function() { content = this.doc.find('.fullnews-content').html(); if(!content.length) content = doc.find('.article-content').html(); return content; } } 

谢谢。

 module.exports = function Post((documentDOM,options) 

我想你的意思

 module.exports.Post = function((documentDOM,options) 

然后像这样访问它

 var Post = require('./post.js').Post; 

首先你要使exports本身成为一个命名函数 ,为了修改它,你可以使用module.exports.prototype

相关学习资料: http : //kangax.github.com/nfe/