Skip to content

Instantly share code, notes, and snippets.

@manekinekko
Last active September 12, 2018 11:15
Show Gist options
  • Save manekinekko/15254455298dee7a20234db78178b40c to your computer and use it in GitHub Desktop.
Save manekinekko/15254455298dee7a20234db78178b40c to your computer and use it in GitHub Desktop.
function every(list, callback) {
for (let i = 0; i < list.length; i += 1) {
callback.call(list, i);
};
}
every(['a', 42, false, {}], (index) => {
console.log('1', this); //=> ['a', 42, false, {}]
console.log('2', this[index]); //=> 'a', 42, false, {}
console.log('3', this[index + 1]); //=> 42, false, {}, undefined
console.log('4', this[index - 1]); //=> undefined, 'a', 42, false
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment