Skip to content

Commit

Permalink
Add hack to make this._super.someMethod available
Browse files Browse the repository at this point in the history
  • Loading branch information
jgwhite committed Jan 24, 2015
1 parent da8f632 commit 029e3fb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/assign-properties.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function giveMethodSuper(target, fn) {
function giveMethodSuper(name, target, fn) {
return function() {
var previous = this._super;
this._super = target;
this._super[name] = target;
var ret = fn.apply(this, arguments);
this._super = previous;
return ret;
Expand Down Expand Up @@ -36,9 +37,9 @@ function assignProperties(target, options) {
if (typeof value === 'function' &&
hasSuper(value)) {
if (typeof target[key] === 'function') {
target[key] = giveMethodSuper(target[key], value);
target[key] = giveMethodSuper(key, target[key], value);

This comment has been minimized.

Copy link
@chadhietala

chadhietala Jan 24, 2015

It might be better to rename target to context and do:

giveMethodSuper(context, key, value);

You then put the lookup in giveMethodSuper. You'll still need to pivot off of target[key], but this feels more like a .apply or .call call on a function and is a little more clear on why you have to pass it. Just a thought.

This comment has been minimized.

Copy link
@jgwhite

jgwhite Jan 24, 2015

Author Owner

That's definitely an improvement.

To be clear though, this is only proposed as an interim fix (hack) at best.

} else {
target[key] = giveMethodSuper(function() { }, value);
target[key] = giveMethodSuper(key, function() { }, value);
}
} else {
target[key] = value;
Expand Down

0 comments on commit 029e3fb

Please sign in to comment.