Js Equivalent of Ruby send method

less than 1 minute read

Do you remember we talked about ruby’s send method here. It is used to call a ruby function from string having same value as function name.

There is js equivalent of the same:

// defining the function
var apple = function(){
	console.log('apple');
}

eval('apple()') // => apple

Reference:

  1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval
  2. http://www.2ality.com/2014/01/eval.html

Categories:

Updated:

Leave a Comment