Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing callSuper #3844

Merged
merged 3 commits into from Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mixins/itext_behavior.mixin.js
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
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
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