问题

问题一://实现效果 [1,2,3,4,5].duplicator(); 输出结果: [1,2,3,4,5,1,2,3,4,5]
/*
在控制台中测试,返回方式不同却出现了不同结果。
难道return 和console.log()在返回和显示结果的时候有区别?
*/
Array.prototype.duplicator = function() {
var b = [],
a = this;
b = this.concat(a);
console.log(b);
}

[1, 2, 3, 4, 5].duplicator();
//[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, duplicator: function]
//后面加一个function是怎么回事?console.log()会使用in?????

Array.prototype.duplicator = function() {
var b = [],
a = this;
b = this.concat(a);
return b;
}

[1, 2, 3, 4, 5].duplicator();
//[1, 2, 3, 4, 5, 1, 2, 3, 4, 5]

  

posted @ 2014-08-28 18:08  xiaohong_oath  阅读(235)  评论(0编辑  收藏  举报