04-08-2013, 08:24 AM
Fiecare funcție în Javascript este o instanta a obiectului Function:
Funcția “add” de mai sus poate fi, de asemenea, definită folosind următorul model.
O instanță a unei funcți are proprietăți și metode.
Code:
//x,y este argumentul. 'return x+y' este corpul funcției, care este ultimul în lista de argumente.
var add = new Function ( 'x' , 'y' , 'return x+y' ) ;
var t = add ( 1 , 2 ) ;
alert ( t ) ; //3Code:
function add ( x , y ) {
return x + y ;
}
var t = add ( 1 , 2 ) ;
alert ( t ) ; //3Code:
function subtract ( x , y )
{
return x - y ;
}
alert ( subtract. length ) ; //2,expected amount of arguments.
alert ( subtract. toString () );
/*
function subtract(x, y)
{
return x - y;
}
*/