2020-05-03 18:59:26 +02:00
|
|
|
/* global Class, xyz */
|
|
|
|
|
2016-03-24 17:19:32 +01:00
|
|
|
/* Simple JavaScript Inheritance
|
2020-04-28 23:05:28 +02:00
|
|
|
* By John Resig https://johnresig.com/
|
2020-05-03 18:59:26 +02:00
|
|
|
*
|
|
|
|
* Inspired by base2 and Prototype
|
|
|
|
*
|
2016-03-24 17:19:32 +01:00
|
|
|
* MIT Licensed.
|
|
|
|
*/
|
2017-07-17 14:23:24 +02:00
|
|
|
(function () {
|
2016-04-05 14:35:11 -04:00
|
|
|
var initializing = false;
|
2020-05-11 22:22:32 +02:00
|
|
|
var fnTest = /xyz/.test(function () {
|
|
|
|
xyz;
|
|
|
|
})
|
|
|
|
? /\b_super\b/
|
|
|
|
: /.*/;
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2016-04-05 14:35:11 -04:00
|
|
|
// The base Class implementation (does nothing)
|
2020-05-11 22:22:32 +02:00
|
|
|
this.Class = function () {};
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2016-04-05 14:35:11 -04:00
|
|
|
// Create a new Class that inherits from this class
|
2017-07-17 14:23:24 +02:00
|
|
|
Class.extend = function (prop) {
|
2016-04-05 14:35:11 -04:00
|
|
|
var _super = this.prototype;
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2016-04-05 14:35:11 -04:00
|
|
|
// Instantiate a base class (but only create the instance,
|
|
|
|
// don't run the init constructor)
|
|
|
|
initializing = true;
|
|
|
|
var prototype = new this();
|
|
|
|
initializing = false;
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2019-06-05 09:46:59 +02:00
|
|
|
// Make a copy of all prototype properties, to prevent reference issues.
|
2020-04-21 07:36:18 +02:00
|
|
|
for (var p in prototype) {
|
|
|
|
prototype[p] = cloneObject(prototype[p]);
|
2016-10-13 14:25:53 +02:00
|
|
|
}
|
|
|
|
|
2016-04-05 14:35:11 -04:00
|
|
|
// Copy the properties over onto the new prototype
|
|
|
|
for (var name in prop) {
|
|
|
|
// Check if we're overwriting an existing function
|
2020-05-11 22:22:32 +02:00
|
|
|
prototype[name] =
|
|
|
|
typeof prop[name] === "function" && typeof _super[name] === "function" && fnTest.test(prop[name])
|
|
|
|
? (function (name, fn) {
|
|
|
|
return function () {
|
|
|
|
var tmp = this._super;
|
|
|
|
|
|
|
|
// Add a new ._super() method that is the same method
|
|
|
|
// but on the super-class
|
|
|
|
this._super = _super[name];
|
|
|
|
|
|
|
|
// The method only need to be bound temporarily, so we
|
|
|
|
// remove it when we're done executing
|
|
|
|
var ret = fn.apply(this, arguments);
|
|
|
|
this._super = tmp;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
})(name, prop[name])
|
|
|
|
: prop[name];
|
2016-04-05 14:35:11 -04:00
|
|
|
}
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2016-04-05 14:35:11 -04:00
|
|
|
// The dummy class constructor
|
|
|
|
function Class() {
|
|
|
|
// All construction is actually done in the init method
|
2016-05-03 19:09:38 -04:00
|
|
|
if (!initializing && this.init) {
|
|
|
|
this.init.apply(this, arguments);
|
|
|
|
}
|
2016-04-05 14:35:11 -04:00
|
|
|
}
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2016-04-05 14:35:11 -04:00
|
|
|
// Populate our constructed prototype object
|
|
|
|
Class.prototype = prototype;
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2016-04-05 14:35:11 -04:00
|
|
|
// Enforce the constructor to be what we expect
|
|
|
|
Class.prototype.constructor = Class;
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2016-04-05 14:35:11 -04:00
|
|
|
// And make this class extendable
|
|
|
|
Class.extend = arguments.callee;
|
2016-04-03 19:52:13 +02:00
|
|
|
|
2016-04-05 14:35:11 -04:00
|
|
|
return Class;
|
|
|
|
};
|
2016-03-30 13:44:16 +02:00
|
|
|
})();
|
|
|
|
|
2016-10-14 15:23:03 +02:00
|
|
|
//Define the clone method for later use.
|
|
|
|
//Helper Method
|
|
|
|
function cloneObject(obj) {
|
|
|
|
if (obj === null || typeof obj !== "object") {
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
var temp = obj.constructor(); // give temp the original obj's constructor
|
|
|
|
for (var key in obj) {
|
|
|
|
temp[key] = cloneObject(obj[key]);
|
2016-12-29 22:23:08 -03:00
|
|
|
|
2016-10-14 15:23:03 +02:00
|
|
|
if (key === "lockStrings") {
|
|
|
|
Log.log(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
2016-03-30 13:44:16 +02:00
|
|
|
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
2017-07-25 21:36:30 -04:00
|
|
|
if (typeof module !== "undefined") {
|
|
|
|
module.exports = Class;
|
|
|
|
}
|