参数arguments

1.定义方法log,输出log("hello world");

   function log(msg){

        console.log(msg);

   }

 

2.传入多个参数log("hello", "world"):

    function log(){

        console.log.apply(console, arguments);

    }

 

3.给每个log消息添加“(app)”前缀:

    function log(){

         var args = Array.prototype.slice.call(arguments);   //将参数数组由伪数组转化为标准数组

         args.unshift("(app)");

         console.log.apply(console, args);

    }

 

posted @ 2016-09-24 17:54  西风.烈马  阅读(131)  评论(0编辑  收藏  举报