不要怂,就是干,撸起袖子干!

Commit b1d18c2b by Sascha Depold

use bind instead of self

1 parent 9c50f794
Showing with 6 additions and 10 deletions
...@@ -3,8 +3,6 @@ var Utils = require("../../utils") ...@@ -3,8 +3,6 @@ var Utils = require("../../utils")
module.exports = (function() { module.exports = (function() {
var Query = function(client, sequelize, callee, options) { var Query = function(client, sequelize, callee, options) {
var self = this
this.client = client this.client = client
this.callee = callee this.callee = callee
this.sequelize = sequelize this.sequelize = sequelize
...@@ -15,14 +13,12 @@ module.exports = (function() { ...@@ -15,14 +13,12 @@ module.exports = (function() {
}, options || {}) }, options || {})
this.checkLoggingOption() this.checkLoggingOption()
this.bindClientFunction = function(err) { onFailure.call(self, err) } this.bindClientFunction = function(err) { onFailure.call(this, err) }.bind(this)
} }
Utils.inherit(Query, require('../abstract/query')) Utils.inherit(Query, AbstractQuery)
Query.prototype.run = function(sql) { Query.prototype.run = function(sql) {
var self = this
this.sql = sql this.sql = sql
bindClient.call(this) bindClient.call(this)
...@@ -32,18 +28,18 @@ module.exports = (function() { ...@@ -32,18 +28,18 @@ module.exports = (function() {
} }
this.client.query({ sql: this.sql, nestTables: true }, function(err, results, fields) { this.client.query({ sql: this.sql, nestTables: true }, function(err, results, fields) {
self.emit('sql', self.sql) this.emit('sql', this.sql)
if (err) { if (err) {
onFailure.call(self, err) onFailure.call(this, err)
} else { } else {
if (Array.isArray(results) && !!results[0] && Utils._.keys(results[0]).length === 1) { if (Array.isArray(results) && !!results[0] && Utils._.keys(results[0]).length === 1) {
results = results.map(function(result){ return Utils._.values(result)[0] }) results = results.map(function(result){ return Utils._.values(result)[0] })
} }
onSuccess.call(self, results, fields) onSuccess.call(this, results, fields)
} }
}).setMaxListeners(100) }.bind(this)).setMaxListeners(100)
return this return this
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!