Dynamic method call from string with args - node.js

Problem

I want to write a little function which receive an array of objects which describe rule(s) to check, using node-validator.

I wrote this:

http://pastebin.com/gWarw98P

The error is at the line 68. I'm using the same example than describe in the method description. And I have to manage args dynamically too.

If I replace:

check(value, rule[j].message).rule[j]['function']();

By

check(value, rule[j].message).isNumeric();

It works. So my main problem is to call the good method...

Can you help me?

Problem courtesy of: Vadorequest

Solution

If you want to get the property of the object returned by check() based on the value of rule[j]['function'], you need to use bracket notation:

check(value, rule[j].message)[rule[j].function]();
Solution courtesy of: Ryan

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.