Skip to content

Commit 2a1f439

Browse files
daeyeonyichoi
authored andcommitted
Fix util.mixin for use in common objects (#1580)
IoT.js-DCO-1.0-Signed-off-by: Daeyeon Jeong [email protected]
1 parent bb84bec commit 2a1f439

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/js/uart.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
var EventEmitter = require('events').EventEmitter;
1717
var util = require('util');
1818

19-
util.mixin(native, EventEmitter);
19+
util.mixin(native.prototype, EventEmitter.prototype);
2020

2121
var uart = {
2222
open: function(config, callback) {

src/js/util.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,23 @@ function inherits(ctor, superCtor) {
7474
}
7575

7676

77-
function mixin(target, source) {
78-
for (var prop in source.prototype) {
79-
if (source.hasOwnProperty(prop)) {
80-
target.prototype[prop] = source.prototype[prop];
77+
function mixin(target) {
78+
if (isNullOrUndefined(target)) {
79+
throw new TypeError('target cannot be null or undefined');
80+
}
81+
82+
for (var i = 1; i < arguments.length; ++i) {
83+
var source = arguments[i];
84+
if (!isNullOrUndefined(source)) {
85+
for (var prop in source) {
86+
if (source.hasOwnProperty(prop)) {
87+
target[prop] = source[prop];
88+
}
89+
}
8190
}
8291
}
92+
93+
return target;
8394
}
8495

8596
function format(s) {

0 commit comments

Comments
 (0)