From 6c539df7fede5b655949bbb21ab7d461d5ecfd22 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Wed, 11 Dec 2024 21:45:38 -0500 Subject: [PATCH 1/3] Allow calling shadowed method when using addMethods. --- public/js/lib/class.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/public/js/lib/class.js b/public/js/lib/class.js index 89479ac845..615d647929 100644 --- a/public/js/lib/class.js +++ b/public/js/lib/class.js @@ -59,6 +59,7 @@ 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++) { @@ -68,8 +69,23 @@ var Class = (function() { var method = value; value = wrap.bind((function(m) { + const method = ancestor[m]; return function() { - return ancestor[m].apply(this, arguments); + return method.apply(this, arguments); + }; + })(property))(method); + + value.valueOf = method.valueOf.bind(method); + value.toString = method.toString.bind(method); + } else if (self && isFunction(value) + // TODO: reduce copy and patin here + && argumentNames(value)[0] == "$this") { + var method = value; + + value = wrap.bind((function(m) { + const method = self[m]; + return function() { + return method.apply(this, arguments); }; })(property))(method); From f243d36f54a2d8aadf11533e79b40f2a3f57557f Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Wed, 11 Dec 2024 22:01:31 -0500 Subject: [PATCH 2/3] cleanup --- public/js/lib/class.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/public/js/lib/class.js b/public/js/lib/class.js index 615d647929..a6a2e130a3 100644 --- a/public/js/lib/class.js +++ b/public/js/lib/class.js @@ -64,9 +64,9 @@ var Class = (function() { 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 method = ancestor[m]; @@ -78,10 +78,8 @@ var Class = (function() { value.valueOf = method.valueOf.bind(method); value.toString = method.toString.bind(method); } else if (self && isFunction(value) - // TODO: reduce copy and patin here && argumentNames(value)[0] == "$this") { - var method = value; - + // TODO: reduce copy and pasting here value = wrap.bind((function(m) { const method = self[m]; return function() { From 44b149240c6ef31862b0b1f58461204147121556 Mon Sep 17 00:00:00 2001 From: Alex Rothberg Date: Wed, 11 Dec 2024 22:04:36 -0500 Subject: [PATCH 3/3] cleanup --- public/js/lib/class.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/js/lib/class.js b/public/js/lib/class.js index a6a2e130a3..5b2e63eec1 100644 --- a/public/js/lib/class.js +++ b/public/js/lib/class.js @@ -69,9 +69,9 @@ var Class = (function() { && argumentNames(value)[0] == "$super") { value = wrap.bind((function(m) { - const method = ancestor[m]; + const shadowMethod = ancestor[m]; return function() { - return method.apply(this, arguments); + return shadowMethod.apply(this, arguments); }; })(property))(method); @@ -81,9 +81,9 @@ var Class = (function() { && argumentNames(value)[0] == "$this") { // TODO: reduce copy and pasting here value = wrap.bind((function(m) { - const method = self[m]; + const shadowMethod = self[m]; return function() { - return method.apply(this, arguments); + return shadowMethod.apply(this, arguments); }; })(property))(method);