JavaScript の Plain Object (ただの) と、関数のみを利用して、Polymorphism を実現したい。
とはいえ Polymorphism の定義は人によって違うので、以下の仕様とルールを満たすものとしたい。
そもそもそれは Polymorphism ではない、あるいは意味をなさない、というような反論があればそれも歓迎。
| const assert = require('assert'); | |
| const _ = require('lodash'); | |
| class Masu { | |
| constructor(isMine, isOpened) { | |
| this.isMine = isMine; | |
| this.isOpened = isOpened; | |
| } | |
| } |
| abstract class A<T> { | |
| a() { return new Map<string, T>(); } | |
| static b(): number { return 1; } | |
| } | |
| class X<T> extends A<T> {} | |
| class Y extends A<number> {} | |
| new X<number>().a(); // OK | |
| new Y().a(); // OK | |
| X.b(); // OK |
| # A patch for faraday raise_error middleware for my usecase | |
| # faraday: https://github.com/lostisland/faraday | |
| class Connection | |
| def self.foo_service | |
| Thread.current[:foo_connection] ||= Faraday.new(Rails.application.config.x.foo_service_url) do |conn| | |
| conn.request :json | |
| conn.response :my_raise_error # See below comment | |
| conn.response :json, :content_type => /\bjson$/ |