I would like to do something like this:
"use strict"; // on by default in my babel setup
function create_func(some, params) {
var func = otherstuff => {
console.log("inner", some, otherstuff);
return 4;
};
/*
something here, such as:
func.params = params;
*/
return func;
}
var f = create_func(1,2);
console.log(f.params); // should print 2
var returnval = f(3); // should print "inner", 1, 3
console.log(returnval); // should print 4
This is related to eg how jQuery()
is a function, but jQuery.ajax()
is also an accessible function.
What would be the ideal way to do this in ES5, ES2015, or later?
Here's a question that asks how to do something similar to this, but without the constraint that it be modern JS: Can you create functions with custom prototypes in JavaScript?