ASP/VBScript重载问题
2012-06-11 金城 2372
VBScript不支持重载,但是JavaScript支持
正常情况下,ASP都支持VBScript和JavaScript。重要的是可以混编,晓得了吧。
方法一
<script runat="server" language="javascript">
function test(p1,p2,p3){// 固定参数
//用js的方式处理
if(p1){
if(p2){
if(p3){
// todo p1 and p2 and p3
}else{
// todo p1 and p2
}
}else{
// todo p1
}
}else{
//todo no parameters
}
}
function test2(){// 不定参数
var numargs = arguments.length;
if(numargs==0){}
else if(numargs==1){}
else if(numargs==2){}
//else if(numargs==N){}
}
</script>居然能混编,真爽<%
test
test 5
test 1,2
test "test","abc","haha"
test "XYZ","WWW"
test2 1,2,3,4,5,6,7,8,9,10,"a","b","c","d","e","f","g"
%>
function test(p1,p2,p3){// 固定参数
//用js的方式处理
if(p1){
if(p2){
if(p3){
// todo p1 and p2 and p3
}else{
// todo p1 and p2
}
}else{
// todo p1
}
}else{
//todo no parameters
}
}
function test2(){// 不定参数
var numargs = arguments.length;
if(numargs==0){}
else if(numargs==1){}
else if(numargs==2){}
//else if(numargs==N){}
}
</script>居然能混编,真爽<%
test
test 5
test 1,2
test "test","abc","haha"
test "XYZ","WWW"
test2 1,2,3,4,5,6,7,8,9,10,"a","b","c","d","e","f","g"
%>
方法二
利用或格式化的字符串 或 数组 或 字典对象 做参数
<%
function MyTestStr(strList)
'' 此处省略3万字
end function
function MyTestArr(arr)
'' 此处省略2万字
end function
function MyTestDict(dict)
'' 此处省略八万四千字
end function
MyTestStr "1,2,3,test,abc"
MyTestArr Array(1,2,3,"test","abc")
set dict=server.createobject("scripting.dictionary")
dict.add "p1",1
dict.add "p2",2
dict.add "p3",3
dict.add "p4","test"
dict.add "p4","abc"
MyTestDict dict
%>
function MyTestStr(strList)
'' 此处省略3万字
end function
function MyTestArr(arr)
'' 此处省略2万字
end function
function MyTestDict(dict)
'' 此处省略八万四千字
end function
MyTestStr "1,2,3,test,abc"
MyTestArr Array(1,2,3,"test","abc")
set dict=server.createobject("scripting.dictionary")
dict.add "p1",1
dict.add "p2",2
dict.add "p3",3
dict.add "p4","test"
dict.add "p4","abc"
MyTestDict dict
%>