动态生成函数的方法
由于工作需要,用js写了一个函数,该函数是动态生成的,感觉挺有意思的,分享下。下面是一个小例子:
var getXHR = ( function() {var query = null;if (window.XMLHttpRequest) {query = function() {return new XMLHttpRequest();};} else {var i = 0, id, ids = [ 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0' ];for (; (id = ids[i++]);) {try {new ActiveXObject(id);break;} catch (e) {}}query = function() {try {return new ActiveXObject(id);} catch (e) {}};}return query;})();
??