wizardObject.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * SPDX-FileCopyrightText: 2015 ownCloud, Inc.
  3. * SPDX-License-Identifier: AGPL-3.0-or-later
  4. */
  5. OCA = OCA || {};
  6. (function() {
  7. var initializing = false;
  8. var superPattern = /xyz/.test(function() { xyz; }) ? /\b_super\b/ : /.*/;
  9. /**
  10. * @classdesc a base class that allows inheritance
  11. *
  12. * @abstrcact
  13. * @constructor
  14. */
  15. var WizardObject = function(){};
  16. WizardObject.subClass = function(properties) {
  17. var _super = this.prototype;
  18. initializing = true;
  19. var proto = new this();
  20. initializing = false;
  21. for (var name in properties) {
  22. proto[name] =
  23. typeof properties[name] === "function" &&
  24. typeof _super[name] === 'function' &&
  25. superPattern.test(properties[name]) ?
  26. (function (name, fn) {
  27. return function () {
  28. var tmp = this._super;
  29. this._super = _super[name];
  30. var ret = fn.apply(this, arguments);
  31. this._super = tmp;
  32. return ret;
  33. };
  34. })(name, properties[name]) :
  35. properties[name];
  36. };
  37. function Class() {
  38. if(!initializing && this.init) {
  39. this.init.apply(this, arguments);
  40. }
  41. }
  42. Class.prototype = proto;
  43. Class.constructor = Class;
  44. Class.subClass = arguments.callee;
  45. return Class;
  46. };
  47. WizardObject.constructor = WizardObject;
  48. OCA.LDAP.Wizard.WizardObject = WizardObject;
  49. })();