Passing Function as the Parameter in JavaScript

Sunday, 27 March 2016

This is very important to know that how can we use our methods or functions as the parameter of other function or method. Following example shows that the use of function or method as the parameter of other method or function.

Example 1: ( Callback function with parameter )

Following is the function need to pass as a parameter,


 funcion fun1()
 {
      alert("Funtion needs to be pass");
 }


Following is the function, in which we need to pass the above function as a parameter,


 funcion fun2(fun1CallBack)
 {
      fun1CallBack();
 }


Following is the way to call the fun2() by passing fun1(),


 fun2(fun1);


Example 2: ( Callback function with parameter )

Following example shows how to use our callback function has parameter

Following is the function need to pass as a parameter,


 funcion fun1(name)
 {
 alert("You have entered " + name);
 }


Following is the function, in which we need to pass the above function as a parameter,


 funcion fun2(fun1CallBack)
 {
 fun1CallBack();
 }


Following is the way to call the fun2() by passing fun1(),


 fun2(fun1("Jhon"));
 

No comments:

Post a Comment

 
About Contact Career Advertise Job Support Online Training Acardemic Projects Internship
Copyright © 2016. [ info ].
Design by Herdiansyah Hamzah. & Distributed by Free Blogger Templates
Creative Commons License