construct

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
2
VISIBILITY
Public
PUBLISHED
5 years ago
SIZE
1 KB
Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type.
1 contributor
Install construct as a package?
Copied
npm i @bit/justin-capalbo.ramda.construct
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right
construct (
fn:Function
) : Function

Wraps a constructor function inside a curried function that can be called with the same arguments and returns the same type.

Example
// Constructor function
     function Animal(kind) {
       this.kind = kind;
     };
     Animal.prototype.sighting = function() {
       return "It's a " + this.kind + "!";
     }

     const AnimalConstructor = R.construct(Animal)

     // Notice we no longer need the 'new' keyword:
     AnimalConstructor('Pig'); //=> {"kind": "Pig", "sighting": function (){...}};

     const animalTypes = ["Lion", "Tiger", "Bear"];
     const animalSighting = R.invoker(0, 'sighting');
     const sightNewAnimal = R.compose(animalSighting, AnimalConstructor);
     R.map(sightNewAnimal, animalTypes); //=> ["It's a Lion!", "It's a Tiger!", "It's a Bear!"]
Argument
fn: Function

The constructor function to wrap.

Returns
Function

A wrapped, curried constructor function.

Help and resources