Javascript require另一个require方法中的Method

时间:2017-04-15 09:03:26

标签: javascript require

(有人可能会相应更改标题) 当javascript' require方法被调用时,会发生什么:

var xyz = require('xy')(require('z'));

谢谢

3 个答案:

答案 0 :(得分:1)

无论z模块导出将作为参数传递给从xy导出的函数。

如果xy没有导出某个功能,那么您会收到错误

答案 1 :(得分:1)

它的简称:

var xy  = require('xy');
var z   = require('z');
var xyz = xy(z);

答案 2 :(得分:1)

var gulp = require('gulp-help')(require('gulp'));有效,因为require('gulp-help')会返回一个函数,然后将gulp导出的模块作为参数连同选项

require('gulp-help')(require('gulp'), options);

These are all the options available to be passed to the gulp-help instance, NOT individual tasks.

description - modifies the default help message
aliases - adds aliases to the default help task
hideEmpty - hide all tasks with no help message defined. Useful when including 3rd party tasks
hideDepsMessage - hide all task dependencies
afterPrintCallback - a function to run after the default help task runs

这是

的简短形式
var gulp-help = require('gulp-help');
var gulp = gulp-help(require('gulp'));