"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var Origin = (function () { function Origin() { } return Origin; }()); var Base = (function (_super) { __extends(Base, _super); function Base() { return _super !== null && _super.apply(this, arguments) || this; } return Base; }(Origin)); var A = (function (_super) { __extends(A, _super); function A() { return _super !== null && _super.apply(this, arguments) || this; } return A; }(Base)); var B = (function (_super) { __extends(B, _super); function B() { return _super !== null && _super.apply(this, arguments) || this; } return B; }(Base)); var C = (function (_super) { __extends(C, _super); function C() { return _super !== null && _super.apply(this, arguments) || this; } return C; }(Base)); var D = (function (_super) { __extends(D, _super); function D() { return _super !== null && _super.apply(this, arguments) || this; } return D; }(Base)); var E = (function (_super) { __extends(E, _super); function E() { return _super !== null && _super.apply(this, arguments) || this; } return E; }(Base)); var F = (function (_super) { __extends(F, _super); function F() { return _super !== null && _super.apply(this, arguments) || this; } return F; }(Base)); var list = []; for (var i = 0; i < 1000; i++) { list.push(new D()); } function a() {} function b() {} function c() {} function d() {} function e() {} function f() {} const HANDLER_BY_CONSTRUCTOR = new Map([ [A, a], [B, b], [C, c], [D, d], [E, e], [F, f] ]);
function getCommonElementCreator(element) { if (HANDLER_BY_CONSTRUCTOR.get(element.constructor) !== undefined) { return HANDLER_BY_CONSTRUCTOR.get(element.constructor); } let prototype = Object.getPrototypeOf(Object.getPrototypeOf(element));
while (prototype && prototype !== Base.prototype) { const elementType = HANDLER_BY_CONSTRUCTOR.get(prototype.constructor); if (elementType !== undefined) { return elementType; } prototype = Object.getPrototypeOf(prototype); } return; }
list.forEach(function (element) { if (element instanceof A) { a(); } else if (element instanceof B) { b(); } else if (element instanceof C) { c(); } else if (element instanceof D) { d(); } else if (element instanceof E) { e(); } else if (element instanceof F) { f(); } });
list.forEach(function (element) { const handler = getCommonElementCreator(element); if (handler)( handler() ) });
|