Skip to content

Commit

Permalink
fixing callSuper (#3844)
Browse files Browse the repository at this point in the history
* fixing callSuper

* fixing lint

* fixed unexpected alias for this
  • Loading branch information
sirrodgepodge authored and asturur committed Apr 22, 2017
1 parent bdc97a8 commit aef7372
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/mixins/itext_behavior.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
onDeselect: function() {
this.isEditing && this.exitEditing();
this.selected = false;
this.callSuper('onDeselect');
},

/**
Expand Down
7 changes: 7 additions & 0 deletions src/mixins/object_origin.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@
*/
_getLeftTopCoords: function() {
return this.translateToOriginPoint(this.getCenterPoint(), 'left', 'top');
},

/**
* Callback; invoked right before object is about to go from active to inactive
*/
onDeselect: function() {
/* NOOP */
}
});

Expand Down
22 changes: 19 additions & 3 deletions src/util/lang_class.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,26 @@
function Subclass() { }

function callSuper(methodName) {
var fn = this.constructor.superclass.prototype[methodName];
var parentMethod = null,
_this = this;

// climb prototype chain to find method not equal to callee's method
while (_this.constructor.superclass) {
var superClassMethod = _this.constructor.superclass.prototype[methodName];
if (_this[methodName] !== superClassMethod) {
parentMethod = superClassMethod;
break;
}
_this = _this.constructor.superclass.prototype;
}

if (!parentMethod) {
return console.log('tried to callSuper ' + methodName + ', method not found in prototype chain', this);
}

return (arguments.length > 1)
? fn.apply(this, slice.call(arguments, 1))
: fn.call(this);
? parentMethod.apply(this, slice.call(arguments, 1))
: parentMethod.call(this);
}

/**
Expand Down

0 comments on commit aef7372

Please sign in to comment.