Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 1774

How to bind to a function that returns a class

$
0
0

A friend stumped me. He’s using a Javascript library that has some sort of strategy pattern where a function returns a class depending on (I dunno what :man_shrugging:t3:). I can’t find any way (other than using %%raw to make a saner API) to stick an @new on a class that is returned by another function.

Example JS code:

class Foo {
  bar() {
      console.log("bar called")
    }
 }

 function getFoo() {
    // returns a class, how silly
    return Foo
  }

// how to model this is rescript?
  new (getFoo())().bar()

I don’t want to admit that %%raw is the only solution here. :smiley: Any thoughts?

For completeness, here is a link to the %%raw solution.


Viewing all articles
Browse latest Browse all 1774

Trending Articles