Discuss
/
JavaScript
/
对于版本对象判断不用这么麻烦
对于版本对象判断不用这么麻烦
Topic sourcereq = typeof XMLHttpRequest !== "undefined" ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
以上都可以,您这样,老IE的js解释器会报错:Uncaught ReferenceError =》XMLHttpRequest is not defined,
未定义的量(type==="undefined")分两种:
1. 查无此量(Uncaught ):无法对其赋值和读值
2. 查有此量或属于对象,但未赋值(undefined ):可以对其赋值和读值(undefined),比如给object赋予ifdef属性:object.ifdef="defined"
- 1
一库嘟