javascript - js call execution process
迷茫
迷茫 2017-05-19 10:37:03
0
5
466
window._ = {
    VARSION:"0.1.0",
    each:function(obj,iterator,context){
        var index = 0;
        try{
            if(obj.forEach){
                obj.forEach(iterator,context);
            }else if(obj.length){
                for( var i= 0; i<obj.length; i++){
                    iterator.call(context,obj[i],i);
                }
            }else if(obj.each){
                obj.each(function(value){
                    iterator.call(context,value,index++)
                });
            }else{
                var i = 0;
                for(var key in obj){
                    var value = obj[key],
                        pair = [key,value];
                    pair.key = key;
                    pair.value = value;
                    iterator.call(context,pair,i++);
                }
            }
        }catch(e){
            console.log(e)
            // if(e != "__break__") throw e;
        }
        return obj;
    }
}
var arr = {
    a:5,
    b:6,
    c:4
}
_.each(arr,function(a,b){
    console.log(a)
    console.log(b)
})

Img cannot be uploaded due to network speed. Sorry
I want to know the specific function of that call in this code.
What is the execution process? Thank you all

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!