Monday, July 29, 2013

Javascript :: Pass function as parameter

Javascript allows you to pass functions as parameter to another function and that makes Javascript super awesome!. Great things can be achieved from this power.

Quote from Mozilla developer website:

In JavaScript, functions are first-class objects, i.e. they are objects and can be manipulated and passed around just like any other object.

Every Javascript function is a Function object. Hence we can pass them as arguments, like any other object.

How to do that?

Passing function as parameter is no different from passing any other object when it comes to syntax.

I am gonna try and explain that with an example (hopefully, easy to understand)

Related Posts Plugin for WordPress, Blogger...