Created
February 27, 2018 18:05
-
-
Save akinjide/3a3d9ff35458e026ca95d1a2e27a8de5 to your computer and use it in GitHub Desktop.
Callback
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
Array.prototype.click = function(fn, thisArg) { | |
const _self = thisArg || this; | |
for (let i = 0; i < _self.length; i++) { | |
fn.apply(thisArg, [_self[i], i, thisArg]); | |
// Mutation. | |
thisArg.values[i] = i; | |
} | |
}; | |
let values = ['Hello', 'World']; | |
values.click(function(value, index, ctx) { | |
console.log(value, index); | |
}, this); | |
console.log(values, this.values); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment