Created
May 13, 2016 11:08
-
-
Save svapreddy/41a70efd54ba991cf21c248da9acec1f to your computer and use it in GitHub Desktop.
This file contains 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
Problem: https://gist.github.com/timoxley/a34546c28c92025d040a391400ba5eb7 | |
Solution: fns.forEach([].forEach.bind([1])) | |
Explanation: [].forEach.bind(someArray) will return a forEach function binded with passed `someArray`. So we can use this as iterator for `fns.forEach`. But the problem is fns.forEach will be executed `fns.length` times on `[].forEach.bind(someArray)` So each function inside fns will be called fns.length times. | |
fns.forEach.call(fns, [].forEach.call(fns)) // Will execute each function fns.length times | |
fns.forEach.call(fns, [].forEach.call([1,2])) // Will execute each function 2 times | |
fns.forEach.call(fns, [].forEach.call([1])) // Will execute each function 1 time | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment