fixing callSuper (#3844)

* fixing callSuper

* fixing lint

* fixed unexpected alias for this
This commit is contained in:
Roger Beaman 2017-04-20 07:43:58 -04:00 committed by Asturur
parent bdc97a8132
commit aef73726ea
3 changed files with 27 additions and 3 deletions

View file

@ -18,6 +18,7 @@
onDeselect: function() {
this.isEditing && this.exitEditing();
this.selected = false;
this.callSuper('onDeselect');
},
/**

View file

@ -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 */
}
});

View file

@ -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);
}
/**