Demethodize Primitive Methods into generic functions

JS
S
JavaScript

Expose primitive methods to variables (exposed then as generic functions) Source: http://www.reddit.com/r/javascript/comments/2hz1r8/5_array_methods_that_you_should_be_using_now/ckxl70o

1// Demethodizing the Array method, forEach(),  into a generic "each"
2const each = Function.prototype.call.bind([].forEach);
3
4// Sample
5function bold(node){
6   node.style.fontWeight ="bold";
7}
8var nodeList = document.querySelectorAll("p");
9each(nodeList,bold);
10
11
12

Created on 8/10/2018