日期:2014-05-16  浏览次数:20371 次

[ExtJS3.2源码每天一小时](2)ext-base.js做了什么(之四)
//url追加方法,可传入url地址与拼接的key=value串。不推荐使用,因为每次都要判断url中是否有“?”,效率偏低
urlAppend : function(url, s){
    if(!Ext.isEmpty(s)){
        return url + (url.indexOf('?') === -1 ? '?' : '&') + s;
    }
    return url;
}


//截取数组元素的方法,在ie下与其他浏览器的实现有所区别 a-原数组 i-起始位置 j-终止位置(这是一个自运行函数,当ext-base加载完后,就确定了是调用第一个function还是第二个function了)
 toArray : function(){
             return isIE ?
                 function(a, i, j, res){
                     res = [];
                     for(var x = 0, len = a.length; x < len; x++) {
                         res.push(a[x]);
                     }
                     return res.slice(i || 0, j || res.length);
                 } :
                 function(a, i, j){
                     return Array.prototype.slice.call(a, i || 0, j || a.length);
                 }
}()



//判断对象是否可迭代遍历,一般是指数组
isIterable : function(v){ 
            //check for array or arguments
            //检验v是数组或者arguments对象
            if(Ext.isArray(v) || v.callee){
                return true;
            }
            //check for node list type
            //调用对象的toString之后验证是否是集合或者节点集对象
            if(/NodeList|HTMLCollection/.test(toString.call(v))){
                return true;
            }
            //NodeList has an item and length property
            //IXMLDOMNodeList has nextNode method, needs to be checked first.
            return ((typeof v.nextNode != 'undefined' || v.item) && Ext.isNumber(v.length));
        }