【发布时间】:2016-03-08 02:09:07
【问题描述】:
我想在一个函数中调用一个回调函数。所以我不知道该怎么做
function call(){
pg.connect(conString, function(err, client, done) {
if(err) {
return console.error('error fetching client from pool', err);
}
client.query('INSERT into post1 (data) VALUES ($n)', function(err, result) {
//call `done()` to release the client back to the pool
done();
if(err) {
return console.error('error running query', err);
}
console.log(result.rows[0].number);
//output: 1
});
});
}
board.on("ready", function() {
// Create a new generic sensor instance for
// a sensor connected to an analog (ADC) pin
var sensor = new five.Sensor("A0");
// When the sensor value changes, log the value
sensor.on("change", function() {
var n = this.value();
//i want to call that function here
});
});
我也想在另一个回调函数中调用这个函数,这是正确的方法还是建议我正确的方法。
【问题讨论】:
标签: javascript jquery node.js callback