Skip to content

Commit 5fd6096

Browse files
authored
Check for function before trying to copy symbols (#15)
1 parent beab9ac commit 5fd6096

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎lib/proto.js‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
var HAS_SYMBOLS = typeof Object.getOwnPropertySymbols === 'function';
1919

2020
function makeSuper (_super, old, name, fn) {
21+
var isFunction = typeof old === 'function';
2122
var newMethod = function () {
2223
var tmp = this._super;
2324

2425
// Add a new ._super() method that is the same method
2526
// but either pointing to the prototype method
2627
// or to the overwritten method
27-
this._super = (typeof old === 'function') ? old : _super[name];
28+
this._super = isFunction ? old : _super[name];
2829

2930
// The method only need to be bound temporarily, so we
3031
// remove it when we're done executing
@@ -35,9 +36,11 @@
3536
return ret;
3637
};
3738

38-
Object.getOwnPropertySymbols(old).forEach(function (name) {
39-
newMethod[name] = old[name];
40-
});
39+
if (isFunction) {
40+
Object.getOwnPropertySymbols(old).forEach(function (name) {
41+
newMethod[name] = old[name];
42+
});
43+
}
4144

4245
return newMethod;
4346
}

‎test/test.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ describe('UberProto', function () {
4848
Obj.mixin({
4949
test: function () {
5050
return this._super() + ' mixed in';
51+
},
52+
otherTest: function () {
53+
return typeof this._super === 'function';
5154
}
5255
});
5356

5457
assert.equal(inst.test(), 'Tester mixed in');
5558
assert.ok(Obj.test[testProp], 'Symbol conserved on method (Obj)');
5659
assert.ok(inst.test[testProp], 'Symbol conserved on method (inst)');
60+
assert.ok(!inst.otherTest());
5761
});
5862

5963
it('creates a new object', function () {

0 commit comments

Comments
 (0)