帮忙解释下javascript文件

来源:百度知道 编辑:UC知道 时间:2024/06/06 05:42:25
function NiftyCheck(){
if(!document.getElementById || !document.createElement)
return(false);
isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);
if(Array.prototype.push==null){Array.prototype.push=function(){
this[this.length]=arguments[0]; return(this.length);}}
return(true);
}

详细点,谢谢啦。
isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);
正则表达式能解释下吗?

Array.prototype.push是什么意思?

arguments[0]是什么意思?
这些都很奇怪的数组,我不明白。

补充 isXHMTL = ...
/ / 之间这个是个正则,test函数用于正则函数参数。

正则表达式:js的内置对象RegExp。
var reg = new RegExp("pattern", "gi");
或者 简化用 / / 代表一个正则;
参考:
http://www.itlearner.com/code/js_ref/corea3.htm#1158210

Array也是js的内置对象,prototype是对象原型,Array.prototype.push就是为属于Array这个对象的原型定义它的push函数为什么,那么var arr = new Array();后就可以用 arr.push() 来调用你写的这个方法。

arguments是js函数里默认的参数集合。

我们一句一句来看吧:

function NiftyCheck(){
?定义函数
if(!document.getElementById || !document.createElement)
return(false);
?如果浏览器不支持 或者 不能创建对象 则返回false
isXHTML=/html\:/.test(document.getElementsByTagName('body')[0].nodeName);
?取web中对象的标签
if(Array.prototype.push==null){Array.prototype.push=function(){
?如果Array.prototype.push中为空 那么把上面取得的标签存放进去
this[this.length]=arguments[0]; return(this.length);}}