简体   繁体   中英

Javascript require Method within another require method

(Someone may change the title accordingly) What happens exactly when javascript's require method is called like this:

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

thank you

Whatever the z module exports will be passed in as an argument to the function that is being exported from xy .

If xy doesn't export a function, then you would get an error

It's short for this:

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

var gulp = require('gulp-help')(require('gulp')); works because require('gulp-help') returns you a function and then that takes the module exported by gulp as an argument, along with the options

like

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

This is a short form for

var gulp-help = require('gulp-help');
var gulp = gulp-help(require('gulp'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM