I took a combo approach on a recent project:
https://github.com/mathiasbynens/benchmark.js/blob/master/benchmark.js#L81
// I allow `fn` because test `fn` is required
new Benchmark(fn);
// or a name first because other devs require a name too (an options
object for just a name is bulky) and...
new Benchmark('foo', fn);
// arguments after a line break can look ugly for general use
new Benchmark('foo', function() {
// guts
});
// and finally for devs who want to customize things
new Benchmark('foo', fn, options);
// or
new Benchmark(fn, options);
It's easy to juggle the arguments because `name` is a string , `fn` is
a function, and `options` is an object by default.
I do similar things throughout the code base, like
https://github.com/mathiasbynens/benchmark.js/blob/master/benchmark.js#L698
and
https://github.com/mathiasbynens/benchmark.js/blob/master/benchmark.js#L572
- JDD
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]