Javascript猴子补丁rethinkdb .run

我有rethinkdb实例,我使用nodejs客户端。

rethinkdb .db(p.rdb_database) .table(p.table) .orderBy({index: 'uidAndDate'}) .filter({}) .run(rethinkdbConnection, function (error, cursor) {...}) 

有没有什么办法来修补.run函数? 我想像这样监视rethinkdb客户端 – before函数before添加

 rethinkdb .db(p.rdb_database) .table(p.table) .orderBy({index: 'uidAndDate'}) .filter({}) .before(function(error, query, result, next){ console.log('query: ',query); console.log('result: ',result); next(error); }) .run(rethinkdbConnection, function (error, cursor) {...}) 

你可以用这样的东西来修补它

 TermBase = r.expr(1).constructor.__super__.constructor.__super__ TermBase.run_copy = TermBase.run; Termbase.run = function(callback) { console.log("query", this.toString()); this.run_copy(function(error, result) { if (error) { console.log("error", error) } else { console.log("result", result) } callback(error, result) }) }) 

但是那很脏。