Skip to content

Instantly share code, notes, and snippets.

@akinjide

akinjide/callback.js

Created Feb 27, 2018
Embed
What would you like to do?
Callback
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