Created
June 4, 2014 01:19
-
-
Save jikeytang/66e44dca8ff5fee404c6 to your computer and use it in GitHub Desktop.
[ Javascript ] - 20140604-题目1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
如何实现以下代码: | |
[1,2,3,4,5].copy(); // [1,2,3,4,5,1,2,3,4,5] | |
PS: | |
1. 回复时注意加上下面这句话,才会有语法高亮或格式缩进。 | |
```javascript | |
// you code | |
``` | |
2. 粘贴代码时请使用shift+tab,缩进前面的空白。 |
xianlaioy
commented
Jun 4, 2014
if(!('copy' in Array.prototype)){
Array.prototype.copy=function(){
return this.concat(this);
}
}
Array.prototype.copy = function() {
return this.concat(this.slice());
}
var a = [1,2,3,4];
console.log(a.copy());
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment