Created
October 18, 2016 00:29
-
-
Save jordaaash/a340bf42c2d00b397c8e9081cbe924ae to your computer and use it in GitHub Desktop.
Revisions
-
jordaaash created this gist
Oct 18, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ // @flow class SuperClass { something () { } } class SubClass extends SuperClass { } function decorateWithSomethingElse <T: Class<SuperClass>> (SuperClass: T): T { return class SomethingElseAdded extends SuperClass { addSomethingElse () { } } } var SubClassWithSomethingElse = decorateWithSomethingElse(SubClass) // (new SubClass) instanceof SuperClass -> true // (new SubClassWithSomethingElse) instanceof SubClass -> true // (new SubClassWithSomethingElse) instanceof SuperClass -> true