js函数的几种写法

来源:互联网 发布:域名 seo 编辑:程序博客网 时间:2024/06/06 00:23


常见写法:
function Test(){
alert("test");
}
调用:Test()

匿名函数:
var test=function(){
alert("test");
}
调用:test();
写法3:
(function () {  
alert('test');
})();

写法4:
var Test = {
test1:function(){
alert('test1');
}
,test2:function(){
alert('test2');
}
}
使用:var t = Test.test1();

写法5:
var Test = function(){};
Test.prototype={
test1:function(){
alert('test1');
}
,test2:function(){
alert('test2');
}
}
使用:var t = new Test();
t.test2(); 
原创粉丝点击