From e0e431ce78c6991093197f7de49dd6fec7f469ac Mon Sep 17 00:00:00 2001 From: Roger Beaman Date: Thu, 20 Apr 2017 07:43:58 -0400 Subject: [PATCH] fixing callSuper (#3844) * fixing callSuper * fixing lint * fixed unexpected alias for this --- src/mixins/itext_behavior.mixin.js | 1 + src/mixins/object_origin.mixin.js | 7 +++++++ src/util/lang_class.js | 22 +++++++++++++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/mixins/itext_behavior.mixin.js b/src/mixins/itext_behavior.mixin.js index ddd48ae5b74..6f202a3479b 100644 --- a/src/mixins/itext_behavior.mixin.js +++ b/src/mixins/itext_behavior.mixin.js @@ -18,6 +18,7 @@ onDeselect: function() { this.isEditing && this.exitEditing(); this.selected = false; + this.callSuper('onDeselect'); }, /** diff --git a/src/mixins/object_origin.mixin.js b/src/mixins/object_origin.mixin.js index b0bb5c1f98d..19c42cc424f 100644 --- a/src/mixins/object_origin.mixin.js +++ b/src/mixins/object_origin.mixin.js @@ -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 */ } }); diff --git a/src/util/lang_class.js b/src/util/lang_class.js index 9cf6be495e1..19f72460012 100644 --- a/src/util/lang_class.js +++ b/src/util/lang_class.js @@ -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); } /**