diff --git a/public/js/lib/class.js b/public/js/lib/class.js index 89479ac84..5b2e63eec 100644 --- a/public/js/lib/class.js +++ b/public/js/lib/class.js @@ -59,17 +59,31 @@ var Class = (function() { function addMethods(source) { var ancestor = this.superclass && this.superclass.prototype; + const self = this.prototype; var properties = Object.keys(source); for ( var i = 0, length = properties.length; i < length; i++) { var property = properties[i], value = source[property]; + const method = value; if (ancestor && isFunction(value) && argumentNames(value)[0] == "$super") { - var method = value; value = wrap.bind((function(m) { + const shadowMethod = ancestor[m]; return function() { - return ancestor[m].apply(this, arguments); + return shadowMethod.apply(this, arguments); + }; + })(property))(method); + + value.valueOf = method.valueOf.bind(method); + value.toString = method.toString.bind(method); + } else if (self && isFunction(value) + && argumentNames(value)[0] == "$this") { + // TODO: reduce copy and pasting here + value = wrap.bind((function(m) { + const shadowMethod = self[m]; + return function() { + return shadowMethod.apply(this, arguments); }; })(property))(method);