0

I'm trying to write some js function's validation.

Idea: I have checking function, passing to it checked function object, here make sure that all right (or not). I don't want to pass arguments separately, only function object. How can i reach this?

For now i forced to be content with two parameters for checking function - func obj and func arguments

That is what i want:

function checkFunction(func) {
    console.log(func.name);
    console.log(func.arguments);
    // validate something
}

function checkedFunction(a, b, c) {
    checkFunction(checkedFunction...);
    // do something
}

That is what i have now:

function checkFunction(func, args) {
    console.log(func.name);
    console.log(args);
    // validate something
}

function checkedFunction(a, b, c) {
    checkFunction(checkedFunction, arguments);
    // do something;
}
mikewoe
  • 270
  • 2
  • 12
  • 6
    It's not possible - the current arguments the function was called with must be passed along directly somehow (like passing a parameter of `arguments` or with argument rest syntax), they're not a property of the function or anything. – CertainPerformance Mar 27 '19 at 07:58
  • The name of the function is misleading: you're not checking a function, you're checking a function call. – trincot Mar 27 '19 at 08:04
  • You can get function arguments names. Read this [How to get function parameter names/values dynamically?](https://stackoverflow.com/questions/1007981/how-to-get-function-parameter-names-values-dynamically) – Alex Mar 27 '19 at 08:06
  • @Alexander not my issue, unfortunately. I need arguments for validation (for example not equals to null, etc). – mikewoe Mar 27 '19 at 09:00
  • I think you are talking about callback function? – narayansharma91 Mar 27 '19 at 10:42

0 Answers0