There are no named parameters in Javascript.
But if you do not call a system or compressed function, you can still call it by argument name.
The following is an idea on how to do this:
function myFunction(x, y) { return x + y } function invokeByParams(func, params) { var text = func.toString() var i1 = text.indexOf('(') + 1 var i2 = text.indexOf(')') var args = text.substring(i1, i2).split(',') args = args.map(function(x) { return x.trim() }) args = args.map(function(x) { return params[x.trim()] }) return func.apply(this, args) } invokeByParams(myFunction, { y: 1, x: 2 })
source share