It is Bip Bip Bipool

August 8, 2007

arguments.callee :: javascript

Filed under: javascript, Programming — bipool @ 21:00

If you want to use anonymouse function in javascript then you can easily use arguments.callee

As example :

function makeFactorial(){

return function fact(x)

{

if(x > 1)

return x * argument.callee(x-1)

}

}

makeFactorial()(4) ;

output is 24.

also you can see the arguments by using func_name.arguments

javascript :: function

Filed under: Uncategorized — bipool @ 20:47

There are several ways you can write a function in javaScript.

1. first of all a simple and popular way “Function Statement”.

function  func_name ([param],[param],……[param] ){

// statement

}

2. Second way is “function Operator”

var func_name  = function ([param],[param],……[param] ){

//statement

}

3.  Another way is “function constructor”

var  func_name = new function ([param],[param],……[param] ){

//statement

}

In function operator , you can assign the function to another variable but in function statement You can not do this.

In function operator, you can use array of function . as Example…

var fn = array[  function (x )  {return x;} , function (x )  {return x*x ;},function (x )  {return x*X*x;}

]

for  fn[0](5) , output is 5

for  fn[1](5) , output is 25

for  fn[2](5) , output is 125

Theme: Banana Smoothie. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.