JSFiddle - React, Tailwind, and code Playground
by dsummersl
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.0/lodash.min.js"></script>
<div id='results'></div>
JavaScript
var logFn = function() {
var args = Array.prototype.slice.call(arguments, 0);
$('#results').append('<br>'+ args.join('') +'</br>');
};
// logFn = console.log;
Number.prototype.times = function (cb) {
return _.times(+this, cb);
};
logFn('Version 1: with #s');
// Show the iteraton number after blah:
var result = 5..times(_.partial(logFn,"blah = "));
logFn('Version 1: w/o #s');
// Just show blah:
var result = 5..times(_.ary(_.partial(logFn,"blah")));
// Make the times function apply the partial to whatever params are passed:
Number.prototype.times = function () {
return _.times(+this, _.ary(_.partial.apply(this,arguments)));
};
logFn('Version 2:');
// Show the iteraton number after blah:
var result = 5..times(logFn,"blah");
// You can still use it with an arbitrary function:
var result = 5..times(function() {
logFn("embedded");
});