Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2015年1月23日 D7 希望每日一题能继续,来发简单的。arguments类型转换。 #38

Open
qingo opened this issue Jan 23, 2015 · 15 comments
Labels

Comments

@qingo
Copy link

qingo commented Jan 23, 2015

把arguments转化为array类型。
case:

function arguments2array(){
    // todo code body
}
arguments2array(1); //=> [1]
arguments2array(1, 4, 6); //=> [1, 4, 6]
arguments2array(1, {}); //=> [1, {}]
@qingo qingo changed the title 希望每日一题能继续,来发简单的。argments类型转换。D7 2015年1月7日 D7 希望每日一题能继续,来发简单的。argments类型转换。 Jan 23, 2015
@MeCKodo
Copy link

MeCKodo commented Jan 23, 2015

Array.prototype.slice.call(arguments);

@fireflyhoo
Copy link

//arguments.slice(); 汗

@flybbjcs70
Copy link

[].slice.call(arguments);

@Bosn
Copy link

Bosn commented Jan 23, 2015

function argments2array(){
    return [].slice.call(arguments);
}

每日一水

@zhoufenfens
Copy link

火钳刘明

function argments2array(){
  Array.prototype.slice.call(arguments,0);
}

@qingo qingo changed the title 2015年1月7日 D7 希望每日一题能继续,来发简单的。argments类型转换。 2015年1月7日 D7 希望每日一题能继续,来发简单的。arguments类型转换。 Jan 23, 2015
@wxxcarl
Copy link

wxxcarl commented Jan 23, 2015

return arguments

@zhanglun
Copy link

function argments2array(){
  return Array.prototype.slice.call(arguments,0);
}

@xuyuan923
Copy link

function argments2array(){
return Array.prototype.slice.call(arguments);
}

@llyuan520
Copy link

function test(){ 
  var args = Array.prototype.slice.apply(arguments); 
 alert(args); 
}

@zjh-neverstop
Copy link

function argments2array (){
     try{
         return Array.prototype.slice.call(arguments);
     } catch(e){
         var arr = [];
         for(var i = 0,len = arguments.length; i < len; i++){
             arr[i] = arguments[i];  
         }
    }
    return arr;
}

@nunnly nunnly added the 难度7 label Jan 23, 2015
@qingo qingo changed the title 2015年1月7日 D7 希望每日一题能继续,来发简单的。arguments类型转换。 2015年1月23日 D7 希望每日一题能继续,来发简单的。arguments类型转换。 Jan 23, 2015
@lzbSun
Copy link

lzbSun commented Jan 27, 2015

return Array.prototype.slice.call(arguments);

@ittce
Copy link

ittce commented Jan 27, 2015

function arguments2array(){
return [].slice.call(arguments,0)
}

@helloaspnet
Copy link

function argments2array(){
return arguments.valueOf();
}

@zhoufenfens
Copy link

@helloaspnet 好思路

@VaJoy
Copy link

VaJoy commented Feb 27, 2015

玩点小花样吧,ES5来帮忙

function argments2array(){
    return [].map.call(arguments,function(item){
        return item
    });
}

或者ES6(不过V8都还不支持from方法)

function argments2array(){
    return [].from(arguments)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests