JSFiddle - React, Tailwind, and code Playground
JavaScript
/*
Creates a new function whose prototype is proto.
The function body is the same as the function fbody.
The hash of propertydescriptors props is passed to defineproperties just like
Object.create does.
*/
Function.create = (function() {
var functionBody = function _getFunctionBody(f) {
return f.toString().replace(/.+\{/, "").replace(/\}$/, "");
};
var letters = "abcdefghijklmnopqrstuvwxyz".split("");
return function _create(proto, fbody, props) {
var parameters = letters.slice(0, fbody.length);
parameters.push(functionBody(fbody));
var f = Function.apply(this, parameters);
f.__proto__ = proto;
Object.defineProperties(f, props);
return f;
};
})();
var f = Function.create({
"proto": 43
}, function() { return 44; }, {
"self": { value: 45 }
});
console.log(f());
console.log(f.proto);
console.log(f.self);
console.log(f.hasOwnProperty("proto"));
console.log(f.hasOwnProperty("self"));