DoclerLabs / hexMachina

Releases, issues, documentation, website of hexMachina, framework written in Haxe
http://hexmachina.org
MIT License
44 stars 8 forks source link

Allow getting returned value from instance methods / bound functions. #293

Closed back2dos closed 6 years ago

back2dos commented 6 years ago

I would like support for one of these two:

mercedesFactory = new CarFactory({ brand: 'Mercedes' });
redMercedes = mercedesFactory.makeCar({ color: 'red' });
//or
createMercedes = Car.create.bind("Mercedes")
redMercedes = createMercedes({ color: 'red' });

The main point is to not have to refer to the same values again and again, e.g. if you want to create 1000 Mercedeseseseses (what's the plural here?) then it makes sense to preconfigure some kind of factory (instance or function) in flow. Personally I would prefer the former.

gene-pavlovsky commented 6 years ago

Mercedesi?

FrancisBourre commented 6 years ago

These are the 3 scenarios I've been working on. Every scenario works (tested) with or without argument. Let me know if something's missing.

@context
{
    @public 
    gateway = service.getGatewayURL( url, page );

    @public
    service = new hex.mock.MockService();

    url = "http://localhost/amfphp/";
    page = "gateway.php";
}
@context
{
    @public 
    cloned = closure( service );

    service = new hex.mock.MockService();
    closure = hex.mock.MockService.clone.bind( _, gateway );
    gateway = "http://localhost/amfphp/gateway.php";
}
@context
{
    @public 
    gateway = closure( url );

    @public
    service = new hex.mock.MockService();

    url = "http://localhost/amfphp/";
    page = "gateway.php";

    closure = service.getGatewayURL.bind( _, page );
}