JSFiddle - React, Tailwind, and code Playground

by smacky311

JavaScript

Number.prototype.add = methodize(add);

function methodize(func) {//a function that converts a binary function to a method
    return function (x) {        
            //console.log(x);            
            //console.log(this);
            return func(x,this);            
        }
}

function demethodize(method) {//a function that converts a method to a binary function
        return function(x,y) {
            Number.prototype.m = method;
            return (y).m(x);
        };                  
}

function demethodize2(method) {
    return function(that, y) {
        return method.call(that, y);
    }
}

function add(x, y) {
    return x + y;
}

//console.log((3).add(4));  //7

console.log(demethodize(Number.prototype.add)(5,6)); //11
console.log(demethodize2(Number.prototype.add)(5,6)); //11