node 命令中 & 和 && 的区别

node first.js & node second.js 

执行结果: 
第一次:

  first.js
  second.js

第二次:

  second.js
  first.js

第三次:

  first.js
  second.js

第N次:

  ……

总结: 使用 & 连接符, first.js 和 second.js 的执行顺序不确定

 

node first.js && node second.js    

执行结果: 
第一次:

  first.js
  second.js

第二次:

  first.js
  second.js

第三次:

  first.js
  second.js

第N次:

  ……

总结: 使用 & 连接符, first.js 和 second.js 的执行顺序与命令中指定的先后顺序相同

 

first.js

1 function first(){
2     console.log('first.js');
3 }
4 
5 module.exports = first();

 

second.js

1 function second(){
2     console.log('second.js');
3 }
4 
5 module.exports = second();

 

package.json

 1 {
 2     "name": "logicaloperators",
 3     "version": "1.0.0",
 4     "description": "",
 5     "main": "index.js",
 6     "scripts": {
 7         "and": "node first.js & node second.js",
 8         "andand": "node first.js && node second.js"
 9     },
10     "author": "",
11     "license": "ISC"
12 }

 

posted @ 2017-09-13 16:19  FigureSkating  阅读(1595)  评论(0编辑  收藏  举报