Curry a function using bind

by Hari Menon

JavaScript

function add(a, b) {
    return a + b;
}

console.log(add(2, 3));

var add42 = add.bind(null, 42);	// Currying

console.log(add42(3));

function split(separator, str) {
    return str.split(separator);
}

console.log(split(' ', 'hello world!'));

var splitChars = split.bind(null, '');	// Currying

console.log(splitChars('hello world!'));