我经历npm了npm install <package>命令的奇怪行为.在它自己的专用目录中安装包之前.例如,我输入以下命令:
$ npm i babel-preset-es2015
Run Code Online (Sandbox Code Playgroud)
我只/babel-preset-es2015在/node_modules目录下获得一个目录,如下所示:
node_modules/babel-preset-es2015
Run Code Online (Sandbox Code Playgroud)
现在它填充/node_modules了十几个奇怪的包.在babel-preset-es2015安装时,它会安装大约94个软件包:
这是什么行为?这是正常的吗?它为什么开始发生?它是我误操作的设置之王吗?我的npm和节点版本:
$ npm -v
3.3.12
$ node -v
v5.3.0
Run Code Online (Sandbox Code Playgroud) 我无法理解什么是Promise.race行为.在承诺数组中的第一个承诺实例被解决(被拒绝)后,它是否会停止,忽略所有其余的?
我的目标是在数组中执行所有promise.在任何顺序,但都应该执行.
一个例子.可以说array_of_urls有10个网址.将Promise.race按照任何顺序一个接一个地执行所有10个承诺,还是会在第一个承诺后停止?
.then(array_of_urls => {
// array_of_urls == [10 urls]
let array_of_promises = array_of_urls.map((url) => {
return fetch(url).then(res => {
return res;
});
});
return Promise.race(array_of_promises);
})
.then(each_and_every_result => {
// What does happen here? Will this `then` callback be called 10 times or just one?
})
Run Code Online (Sandbox Code Playgroud)
不要Promise■找方法来执行呢?
PS:
MDN 没有解释是否所有内容都将被执行或将停止:
竞争函数返回一个Promise,其结算方式与第一个通过的承诺结算方式相同.它解决或拒绝,以先发生者为准.
UPD:
对不起,没有解释正确.我确实需要在数组中执行所有promise,但不是这样Promise.all.是的,Promise.all执行all,但它等待所有执行完毕,收集结果然后返回一个包含所有结果的数组.每当这10个中的一个满满时,我需要召唤一个回调.这是没有waithig他们所有人都被收集Promise.all.
为什么 TS 会为此代码抛出错误?我已经定义了一个interface Argswithlength属性,但它仍然抛出:
interface Args {
length: number
}
function log<Args>(arg: Args): Args {
console.log(arg.length); // <= why length doesn't exist?
return arg;
}
$ tsc index.ts
index.ts:11:19 - error TS2339: Property 'length' does not exist on type 'Args'.
11 console.log(arg.length);
~~~~~~
Run Code Online (Sandbox Code Playgroud) 我想用Django而不是Django的默认模板语言来尝试Mako.但是当我尝试导入手册中Template所写的Mako 课程时,我遇到了问题:
from mako.template import Template
mytemplate = Template("hello world!")
print mytemplate.render()
Run Code Online (Sandbox Code Playgroud)
我在Windows cmd中执行此操作并收到此类错误:
C:\Documents and Settings\User>cd C:\py\project\vendor\template\Mako_73 // cd to where I unpacked Mako
C:\py\project\vendor\template\Mako_73>python // run Python interpreter
>>> from mako.template import Template // trying to import and getting an error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".\mako\template.py", line 622
exec code in module.__dict__, module.__dict__
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
该部分的代码:
def _compile_text(template, text, filename):
identifier = template.module_id
source, lexer …Run Code Online (Sandbox Code Playgroud) node.js ×2
asynchronous ×1
generics ×1
javascript ×1
mako ×1
npm ×1
promise ×1
python-3.x ×1
typescript ×1