1、函数是对象,函数名是指针

function sum(num1,num2){

return num1+num2;

}

alert sum(10,10);               //20

var anotherSum=sum;       //函数名是指针

alert(anotherSum(10,10)); //20

 

sum=null;

alert(anotherSum(10,10)); //20

 

2、函数声明

alert(sum(10,10));

function sum(num1,num2){

return num1+num2;                           //可以执行,因为代码执行前,解析器已读取声明并列入执行环境

}

 

alert(sum(10,10));                              //不可执行,此行报错

var sum=function sum(num1,num2){  //以初始化形式定义函数,不能读取声明

return num1+num2;                         

}

 

3、高阶函数

function callSomeFunction(someFunction,someArgument){

return someFunction(someArgument);

}

function add10(num){

return num+10;

}

var result=callSomeFunction(add10,10);

alert(result);

 

4、函数内部属性:arguments与this

this:函数在执行时所处的作用域(在网页全局作用域中调用函数时,this对象引用window)

window.color="red";

var o={color:"blue"};

function sayColor(){

alert(this.color);

}

sayColor();                   //red

o.sayColor=sayColor;   //函数名只是指针变量

o.sayColor();                //blue

 

posted on 2012-01-19 15:54  Ballad1939  阅读(220)  评论(0)    收藏  举报