| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- /**
- * DevExtreme (core/class.js)
- * Version: 19.1.16
- * Build date: Tue Oct 18 2022
- *
- * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
- * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
- */
- "use strict";
- var errors = require("./errors");
- var typeUtils = require("./utils/type");
- var wrapOverridden = function(baseProto, methodName, method) {
- return function() {
- var prevCallBase = this.callBase;
- this.callBase = baseProto[methodName];
- try {
- return method.apply(this, arguments)
- } finally {
- this.callBase = prevCallBase
- }
- }
- };
- var clonePrototype = function(obj) {
- var func = function() {};
- func.prototype = obj.prototype;
- return new func
- };
- var redefine = function(members) {
- var that = this;
- var overridden;
- var memberName;
- var member;
- if (!members) {
- return that
- }
- for (memberName in members) {
- member = members[memberName];
- overridden = "function" === typeof that.prototype[memberName] && "function" === typeof member;
- that.prototype[memberName] = overridden ? wrapOverridden(that.parent.prototype, memberName, member) : member
- }
- return that
- };
- var include = function() {
- var classObj = this;
- var argument;
- var name;
- var i;
- var hasClassObjOwnProperty = Object.prototype.hasOwnProperty.bind(classObj);
- var isES6Class = !hasClassObjOwnProperty("_includedCtors") && !hasClassObjOwnProperty("_includedPostCtors");
- if (isES6Class) {
- classObj._includedCtors = classObj._includedCtors.slice(0);
- classObj._includedPostCtors = classObj._includedPostCtors.slice(0)
- }
- for (i = 0; i < arguments.length; i++) {
- argument = arguments[i];
- if (argument.ctor) {
- classObj._includedCtors.push(argument.ctor)
- }
- if (argument.postCtor) {
- classObj._includedPostCtors.push(argument.postCtor)
- }
- for (name in argument) {
- if ("ctor" === name || "postCtor" === name) {
- continue
- }
- classObj.prototype[name] = argument[name]
- }
- }
- return classObj
- };
- var subclassOf = function(parentClass) {
- if (this.parent === parentClass) {
- return true
- }
- if (!this.parent || !this.parent.subclassOf) {
- return false
- }
- return this.parent.subclassOf(parentClass)
- };
- var abstract = function() {
- throw errors.Error("E0001")
- };
- var copyStatic = function() {
- var hasOwn = Object.prototype.hasOwnProperty;
- return function(source, destination) {
- for (var key in source) {
- if (!hasOwn.call(source, key)) {
- return
- }
- destination[key] = source[key]
- }
- }
- }();
- var classImpl = function() {};
- classImpl.inherit = function(members) {
- var inheritor = function() {
- if (!this || typeUtils.isWindow(this) || "function" !== typeof this.constructor) {
- throw errors.Error("E0003")
- }
- var instance = this;
- var ctor = instance.ctor;
- var includedCtors = instance.constructor._includedCtors;
- var includedPostCtors = instance.constructor._includedPostCtors;
- var i;
- for (i = 0; i < includedCtors.length; i++) {
- includedCtors[i].call(instance)
- }
- if (ctor) {
- ctor.apply(instance, arguments)
- }
- for (i = 0; i < includedPostCtors.length; i++) {
- includedPostCtors[i].call(instance)
- }
- };
- inheritor.prototype = clonePrototype(this);
- copyStatic(this, inheritor);
- inheritor.inherit = this.inherit;
- inheritor.abstract = abstract;
- inheritor.redefine = redefine;
- inheritor.include = include;
- inheritor.subclassOf = subclassOf;
- inheritor.parent = this;
- inheritor._includedCtors = this._includedCtors ? this._includedCtors.slice(0) : [];
- inheritor._includedPostCtors = this._includedPostCtors ? this._includedPostCtors.slice(0) : [];
- inheritor.prototype.constructor = inheritor;
- inheritor.redefine(members);
- return inheritor
- };
- classImpl.abstract = abstract;
- module.exports = classImpl;
|