当前位置: 首页 > 图文教程 > 网络编程 > Javascript > javascript下function声明一些小结

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 javascript下function声明一些小结


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 202 ::
收藏到网摘: n/a

function声明一些东西,我们都知道function和var一样是预处理的在js里面,但是到底什么是函数声明呢,我们来看几个例子 function test(){
return 123;
}

显然这是一个函数声明,那下面的呢
var b=function(){return 123};

这个大家就怀疑了,好似不是声明,因为函数没有名字,只是一个匿名函数,好,再看
var b=function test(){return 123};

这个到底是不是函数声明呢,好象是,那我回答你"不是"
alert(test);
var b=function test(){return 123};

可以在非ie上面任何一个js实现去测试,会报告test未定义错误,那如果这样呢
var b=function test(){return 123};
alert(b);
alert(test);

会显示出function test(){...}这样的函数toString结果,可以第二个alert还是异常,为什么呢,也就是说这里function test(){return 123}不是声明,而是一个函数对象,把引用放到了b里面而已,所以不会象声明一样默认把函数对象绑定到test名字上,那为什么我不叫用ie测试呢,因为
alert(test);
var b=function test(){return 123};

ie会把函数显示出来,ie比较笨,不会区分单独的function声明和=右面的函数对象区别,另外ie甚至还支持function String.prototype.test(){...}这样的声明,可见ie的js bug还真不少了,难怪wilson不支持es4,非得搞一个es3.1出来呢,其实是自己的bug修正版