Skip to content
Akin C edited this page Mar 1, 2019 · 15 revisions

Welcome to the Javascript-bind-and-curry- wiki!

This repository is part of a larger project!

◀️ PREVIOUS PROJECT| NEXT PROJECT ▶️


Currying is a technique which is named after the mathematician and logician Haskell Curry.

By dividing a function`s multiple parameters into another function(s) could be called currying. An example shall now follow:

/*
This function will be curried
function A(x , y , z)
{
    return x * y * z;
}
*/

//The curried version of function "A"
function A(x)
{
    return function B(y)
    {
       return function C(z)
       {
          return x * y * z;
       }
    }
}

//Outputs "4", because "1 * 2 * 2 = 4"
console.log(A(1)(2)(2));

//Another way to call
var a = A(1);
var b = a(2);
var c = b(2);

//Outputs "4"
console.log(c);

This should work because of closures fact two. That means here that the paramter of A is known to B and C and the parameter of B is known to C.

Currying could also be useful when some of the parameters of a function are already known and due this they are defined beforehand. If so then it seems using Javascript`s bind method is recommended. Here follows an example:

function Album(genre, title)
{
    return genre + ": " + title;
}

var List = ["Title 1", "Title 2", "Title 3"];

//Receiver is "null", because in this example 
//there is no need to bind the function to any object
var musicList = List.map(Album.bind(null, "Music"));

/*
    Outputs:
    ["Music: Title1", "Music: Title2", "Music: Title3"]
*/
console.log(musicList);

The parameter genre in Album could be useful when there is more than one list with titles. Every list could be its own genre in that case (e.g. Video, Article, Book).

Content

The user interaction part could look like the content as seen below by starting "index.html" in a web browser and interacting with its features.

ERROR: No image found!

  • 🅱️ utton "RANDOM(Good Luck!)" generates for every input an own youtube video ID

  • The youtube IDs could be given manually if wanted

  • 🅱️ utton "GO" uses the youtube ID to show the found results by the system

To use the project just download the files and execute "index.html". Note that all files(folder "wiki_images" excluded) should be placed in the same folder so that the functionality of the code is guaranteed.

Clone this wiki locally