Răsfoiți Sursa

Handle case where `this` of overridden method is not the pluggable

due for example to it being called by an event handler.
JC Brand 9 ani în urmă
părinte
comite
1666a45c6b
1 a modificat fișierele cu 7 adăugiri și 0 ștergeri
  1. 7 0
      src/converse-pluggable.js

+ 7 - 0
src/converse-pluggable.js

@@ -27,6 +27,13 @@
              * original method.
              */
             if (typeof super_method === "function") {
+                if (typeof this._super === "undefined") {
+                    // We're not on the context of the plugged object.
+                    // This can happen when the overridden method is called via
+                    // an event handler. In this case, we simply tack on the
+                    // _super obj.
+                    this._super = {};
+                }
                 this._super[key] = super_method.bind(this);
             }
             return value.apply(this, _.rest(arguments, 3));