Last active
February 24, 2016 13:32
-
-
Save maousan/ac5e4635c6c6cf498309 to your computer and use it in GitHub Desktop.
array concat deeply!
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
| var jqStyleAdd = function(arr, value) { | |
| var i = 0, len = arr.length; | |
| (function addClass(value, flags) { | |
| if (typeof value === "function") { | |
| arr.forEach(function(elem, j){ | |
| i = j; | |
| addClass(value.call(elem, j, elem), true); | |
| }); | |
| } else if (value) { | |
| arr[i] = value; | |
| if (!flags) { | |
| i++; | |
| while (i != len) { | |
| arr[i++] = value; | |
| } | |
| } | |
| } | |
| })(value); | |
| }; | |
| var arr = [1,2,3,4]; | |
| jqStyleAdd(arr, function(i, value){ | |
| return this + 100; | |
| }); | |
| console.log(arr); | |
| jqStyleAdd(arr, function(i, value){ | |
| return this + 200; | |
| }); | |
| console.log(arr); | |
| jqStyleAdd(arr, 100); | |
| console.log(arr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment