code-quality

Js Equivalent of Ruby send method

js equivalent of ruby send method

Js Equivalent of Ruby send method

Do you remember we talked about ruby’s send method [here]({{ site.url }}/using-send-method-in-ruby-to-refactor-conditional/). 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
About the author

Prakash Poudel Sharma

Engineering Manager · Product Owner · Varicon

Engineering Manager at Varicon, leading the Onboarding squad as Product Owner. Eleven years of building software — first as a programmer, then as a founder, now sharpening the product craft from the inside of a focused team.

Keep reading

More on this

Join the conversation0 comments

What did you take away?

Thoughts, pushback, or a story of your own? Drop a reply below — I read every one.

Comments are powered by Disqus. By posting you agree to theirterms.

0:000:00