Skip to content

Instantly share code, notes, and snippets.

@zbjornson
Created July 11, 2016 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zbjornson/2053cf1a30e893f38f7910dcada712d2 to your computer and use it in GitHub Desktop.
Save zbjornson/2053cf1a30e893f38f7910dcada712d2 to your computer and use it in GitHub Desktop.
(SO question) JS for typescript, trying to create generic factory method on base class
"use strict";
var MyNS;
(function (MyNS) {
var Base = (function () {
function Base() {
}
Base.create = function (foo) {
return new MyNS[foo.type]();
};
return Base;
}());
MyNS.Base = Base;
})(MyNS = exports.MyNS || (exports.MyNS = {}));
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
/// <reference path="Base.ts" />
var MyNS;
(function (MyNS) {
var Descendant = (function (_super) {
__extends(Descendant, _super);
function Descendant() {
_super.apply(this, arguments);
}
Descendant.prototype.echo = function (s) {
return s;
};
return Descendant;
}(MyNS.Base));
MyNS.Descendant = Descendant;
})(MyNS = exports.MyNS || (exports.MyNS = {}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment