小编Gre*_*Fox的帖子

使用Git Clone进行NPM安装

我在GitHub上有一个nodejs项目。我git clone ${GitHubUrl}用来克隆它进行开发。我使用npm install ${GitHubUrl}npm update用于生产。

git clone 为开发/提交设置了一个git repo,但是它没有安装软件包依赖项。

npm install 安装软件包依赖项,但是它没有为开发或提交设置git repo。

是否有将这两者结合在一起的命令?当然,这是一个相当普遍的工作流程,并且有人对此有更好的解决方案。也许类似于git clone ${GitHubUrl}某些npm命令?

这里可以将可行的解决方案提交./node_modules到git repo中,但这有明显的缺点。

javascript node.js

4
推荐指数
1
解决办法
7708
查看次数

Promises如何处理立即解决?

尝试Promises,发现了一些我没想到的东西.

function Delayer(time){
	return new Promise((resolve,reject)=>{
		if(time != 0){
			setTimeout(()=>resolve("Waited " + (time/1000) + " secs!"),time)
		}
		else{
			resolve("No Time Waited");
		}
	})
}
var output = "Promise not resolved yet!";
console.log(output);
Delayer(10).then(function(msg){output = msg; console.log(output)});
console.log(output);//this wont change until callback.
Delayer(0).then(function(msg){output = msg; console.log(output)});
console.log(output);
Run Code Online (Sandbox Code Playgroud)

我希望这个Promise能像这样解决:

> Promise not resolved yet!
> Promise not resolved yet!
> No Time Waited
> No Time Waited
> Waited 3 secs!
Run Code Online (Sandbox Code Playgroud)

相反,我得到3"尚未解决",只有一个"没有时间等待".在处理立即解决之前,它显然正在等待代码的其余部分完成.它是如何做到的?

创建可能立即解决的承诺时,设计最佳实践是什么?

javascript promise

0
推荐指数
1
解决办法
68
查看次数

标签 统计

javascript ×2

node.js ×1

promise ×1