0
任何人都可以解釋下面的代碼中callback()
函數做什麼嗎?這個回調函數來自哪裏?作爲模塊的回調函數。導出參數
index.js
var _ = require('lodash');
var i18n = require('./lib/i18n');
var options = {
stage: 'options:post:configuration'
};
/**
* postprocess
* @param {Object} params
* @param {Function} callback
*/
module.exports = function (params, callback) {
'use strict';
var grunt = params.grunt;
grunt.verbose.subhead('Running:'.bold, '"assemble-contrib-i18n"');
grunt.verbose.writeln('Stage: '.bold, '"' + params.stage + '"\n');
var opts = params.assemble.options.i18n;
grunt.verbose.writeln('Options: '.bold, require('util').inspect(opts));
if (opts) {
var o = {};
var data = opts.data;
var templates = opts.templates;
var languages = opts.languages;
if (templates) {
o.templates = templates;
}
if (languages) {
o.languages = languages;
}
//data = path to a json file containing a list of languages, o = templates & languages
var pages = i18n(data, o);
grunt.verbose.writeln('Pages: '.bold, require('util').inspect(pages));
params.assemble.options.pages = _.extend({}, (params.assemble.options.pages || {}), pages);
}
callback();
};
module.exports.options = options;
和地方被使用了這個index.js
文件在這個文件中gruntfile.js
"with-plugin": {
options: {
plugins: ['./index.js'],
i18n: {
data: ['test/fixtures/data/i18n.json'],
templates: ['test/fixtures/templates/*.hbs']
}
},
dest: 'test/actual/with-plugin/',
src: '!*.*'
},
有啥這裏是回調函數?
嗨,我已更新我的帖子。你能詳細闡述一下在這種情況下什麼是回調函數? – Blake