前端面试心经一.题目

number1:
function _1(){
        console.log(a);
        console.log(b);
        var b=function(){};
        console.log(a);
        console.log(b);
        var a=function(){};
    }

输出结果:....

我的理解:变量的hoisting(提升)

function _11(){
    var a;
    var b;
    console.log(a);//undefined
    console.log(b);//undefined
    b=function(){};
    console.log(a);//undefined
    console.log(b);//Object
    a=function(){};
    
}

 

 代码:


 

 number2:

 先放题目:参考文:http://www.cnblogs.com/littledu/archive/2012/05/19/2508672.html

        :https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/A_re-introduction_to_JavaScript#函数

     arguments正式解释:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Functions/arguments

关于arguments
1.arguments是数组吗?如何将arguments转化为数组?
2.如何从第二项开始转化为数组?

 网版:通过原型连的slice.call(arguments)实现

   function _2(){
        var a=Array.prototype.slice.call(arguments);
        console.log('*********');
        console.log(arguments instanceof Array);
        console.log(a instanceof Array);
        console.log(a.shift());
    }

 

 简单版本:

function toarray(){
    var arr=new Array();
    for(var i= 0,len= arguments.length-1;i<len;i++){
        arr[i]=arguments[i+1];
    }
    return arr;
}

 

好的,解决第二题:

主要考察 arguments call apply 可以参考:http://www.cnblogs.com/sweting/archive/2009/12/21/1629204.html  更详细的研究

Array.prototype.slice2= function (start,end) {
    var start=start||0;
    var end=end||this.length;
    var arr=new Array();
    for(var i=start;i<end;i++){
        arr.push(this[i]);
    }
    return arr;
}
function _4(){
    var _4arr=Array.prototype.slice2.call(arguments,2);
    var _4a=_4arr instanceof Array;
    return _4arr;
}
_4(1,2,3,4,'haha');

 

代码:

number3:

妈蛋写的要死突然屏幕卡了写的都没了...

所以我换另一篇博客写了...待会给链接http://i.cnblogs.com/EditPosts.aspx?postid=4771060

 

posted @ 2015-08-30 15:11  belongcai  阅读(183)  评论(0编辑  收藏  举报