這是一個長鏡頭,但我想知道,如果有這樣的事情作爲C++的std ::綁定在JavaScript或Node.js的?此處,我感到綁定需要的例子:在javascript或node.js中是否存在等價的std :: bind?
var writeResponse = function(response, result) {
response.write(JSON.stringify(result));
response.end();
}
app.get('/sites', function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
dbaccess.exec(query, function(result) {
res.write(JSON.stringify(result));
res.end();
});
});
不是傳遞迴調dbaccesss.exec的,我想傳遞一個函數指針,它有一個參數。在C++中我會通過這樣的:
std::bind(writeResponse, res)
這將導致,它有一個參數(「結果」在我的情況)的函數,我能通過,而不是匿名回調。 現在我重複在匿名函數所有的代碼在我的快遞應用每路線。
[Function.prototype.bind](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind)? – Oka