Add new function proxying as utility function
This commit is contained in:
parent
156a06f316
commit
2c1c691cbc
|
@ -63,12 +63,7 @@ Connection.prototype.connect = function(callback) {
|
|||
var msg = this._logstring("Connecting to");
|
||||
Logger.info(msg);
|
||||
this.adaptor.connect(function() {
|
||||
for (var opt in this.adaptor) {
|
||||
if (!this[opt] && typeof this.adaptor[opt] === 'function') {
|
||||
this[opt] = this.adaptor[opt].bind(this.adaptor);
|
||||
}
|
||||
}
|
||||
|
||||
Utils.proxyFunctions(this.adaptor, this)
|
||||
callback.apply(this, arguments);
|
||||
}.bind(this));
|
||||
};
|
||||
|
|
|
@ -64,12 +64,7 @@ Device.prototype.start = function(callback) {
|
|||
|
||||
Logger.info(msg);
|
||||
this.driver.start(function() {
|
||||
for (var opt in this.driver) {
|
||||
if (!this[opt] && typeof this.driver[opt] === 'function') {
|
||||
this[opt] = this.driver[opt].bind(this.driver);
|
||||
}
|
||||
}
|
||||
|
||||
Utils.proxyFunctions(this.driver, this)
|
||||
callback.apply(this, arguments);
|
||||
}.bind(this));
|
||||
};
|
||||
|
@ -115,7 +110,7 @@ Device.prototype.defaultConnection = function() {
|
|||
|
||||
for (var c in this.robot.connections) {
|
||||
var connection = this.robot.connections[c];
|
||||
first || (first = connection);
|
||||
first = first || connection;
|
||||
}
|
||||
|
||||
return first;
|
||||
|
|
|
@ -100,6 +100,14 @@ var Utils = module.exports = {
|
|||
return child;
|
||||
},
|
||||
|
||||
proxyFunctions: function proxyFunctions(source, target) {
|
||||
for (var opt in source) {
|
||||
if (!target[opt] && typeof source[opt] === 'function') {
|
||||
target[opt] = source[opt].bind(source);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Public: Proxies a list of methods from one object to another. It will not
|
||||
// overwrite existing methods unless told to.
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue