开始学习promise了,关于自己promise模块。求助
Meeting.prototype.getData = function(){
var self = this;
return new Promise(function(resolve,reject){
debug("getData options"+self.options);
var req = http.request(self.options, function(res) {
res.setEncoding('utf8');
var resData = [];
res.on('data', function (chunk) {
resData.push(chunk);
});
res.on('end', function() {
var data = resData.join("");
debug("res end"+data);
return resolve(data);
})
});
req.on('error', function(e) {
debug("problem with request:"+ e.message);
return reject(e.message);
});
debug("req postData:"+ self.postData);
req.write(self.postData);
req.end();
});
};
这里的reject如果reject(e),就会报错是不是就这么写还是其他写法?