您的位置:首页 > 其它

惰性函数

2016-06-03 07:31 253 查看
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
//惰性函数,即对function对象进行更改,但第二次才会执行该函数。
function createXML(){
var xmlHttp;
try{
//-------开始更改----
createXML = function(){
return 	xmlHttp = new XMLHttpRequest();
}
//------------------
}catch(e){
try{
createXML = function(){
return 	xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
}catch(e){
try{
createXML = function(){
return  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}catch(e){
xmlHttp = null;
alert("您的浏览器不支持AJAX!");
}
}
}
return xmlHttp;
}
</script>
</head>
<body>
</body>
</html>


  增加运行速度。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: