Opinions are like assholes, every one has got one.
This one is mine.
Punctuation is a bikeshed. Put your semicolons, whitespace, and commas where you like them.
| 'use strict'; | |
| // This code gets run no matter what, | |
| // so if this dep is slow to load, | |
| // you will pay that tax every time you run `grunt`. | |
| var bigDep = require('big-dependency'); | |
| module.exports = function(grunt) { | |
| grunt.registerTask('my-task', function myTaskFn() { | |
| bigDep(); |
| grunt.registerTask(‘task-a’, function() { | |
| var result = doStuff(); | |
| grunt.registerTask(‘after-task-b’, function() { | |
| doMoreStuff(result); | |
| }); | |
| grunt.task.run(‘task-b’); | |
| grunt.task.run(‘after-task-b’); | |
| }); |
| grunt.registerTask(‘task-a’, function() { | |
| var result = doStuff(); | |
| grunt.task.run(‘task-b’).then(function() { | |
| doMoreStuff(); | |
| }); | |
| }); |
| 'use strict'; | |
| var sdk = require('internal-sdk'); | |
| module.exports = function(grunt) { | |
| sdk(grunt, { | |
| 'project-type': 'widget' | |
| }); | |
| }; |
| "lodash": "^2.4.1" |
| A | |
| └── B | |
| │ └── E | |
| └── C | |
| │ └── E’ | |
| └── D | |
| └── E’’ |
| { | |
| "endpoint": "http://bower.opower.it/", | |
| "searchpath": [ | |
| "https://bower.herokuapp.com" | |
| ], | |
| "registry": { | |
| "search": [ | |
| "http://bower.opower.it/", | |
| "https://bower.herokuapp.com" | |
| ], |
I've been editing this in response to comments below, but I will preserve the full revision history.
Referencing the function execution context via this is fairly common in JavaScript. I suspect some people like it because they come from a language like Java, and it’s familiar. However, I would argue that it in some cases introduces brittleness into one's code without bringing much benefit.
For example, let’s consider a contrived logger module:
function CountingLogger() {
if (!(this instanceof CountingLogger)) return new CountingLogger;| module.exports = function(grunt) { | |
| grunt.initConfig({ | |
| foo: { | |
| options: { | |
| bar: { | |
| minify: true, | |
| scripts: ['a', 'b', 'c'] | |
| } |