Is the on which can dynamically be created, destroyed at runtime during the execution of program,and pass as an argument to other functions. In some languages like javascript and python functions are also first class objects.
Ex. Passing function as an argument in Python:
>>> def op(a,b,fun):
return fun(a,b)
>>> def sum(a,b):
return a+b
>>> op(1,2,sum)
3
>>> def op(a,b,fun):
return fun(a,b)
>>> def sum(a,b):
return a+b
>>> op(1,2,sum)
3
Ex. Dynamically defined function in javascript:
var supriseMe = function () {
alert("Boo!");
supriseMe = function () {
alert(" boooooooo!");
};
};
// using the self-defining function
supriseMe(); // Boo!
supriseMe(); // boooooboo!
Comments
Post a Comment