我见过这样的JavaScript代码:
let a = () => ({ id: 'abc', name: 'xyz' })
Run Code Online (Sandbox Code Playgroud)
( … )在这种情况下,包装对象的括号引用了什么?这是速记return吗?
在使用kubectl端口转发功能时,我能够成功地将本地端口转发到远程端口.然而,似乎在几分钟空转后,连接被丢弃.不知道为什么会这样.
这是用于移植的命令:
kubectl --namespace somenamespace port-forward somepodname 50051:50051
Run Code Online (Sandbox Code Playgroud)
错误信息:
Forwarding from 127.0.0.1:50051 -> 50051
Forwarding from [::1]:50051 -> 50051
E1125 17:18:55.723715 9940 portforward.go:178] lost connection to pod
Run Code Online (Sandbox Code Playgroud)
希望能够保持联系
尝试创建一个函数,该函数返回一个可以解析为null的值的promise
试图做这样的事情
static getUserById(ids: String): Promise<?User> {
// do something
}
Run Code Online (Sandbox Code Playgroud)
但是返回错误
Generic type 'Promise<T>' requires 1 type argument(s)
Run Code Online (Sandbox Code Playgroud)
如何在typescript中创建一个函数,该函数可以返回具有可为空的已解析值的Promise
你如何模拟使用sinon调用回调的外部方法?给出以下代码的示例,getText应该在回调函数中返回'a string'作为响应
sinon.stub(a, 'getText').returns('a string')
let cb = function(err, response) {
console.log(response)
}
a.getText('abc', cb)
Run Code Online (Sandbox Code Playgroud)
它应该产生输出'一个字符串',因为它调用回调函数cb但没有输出
尝试在服务器 grpc 实现未指定回调函数的情况下为 grpc 连接创建超时,但是似乎无论在选项 (new Date().getSeconds()+5) 中指定了什么,客户端不终止连接
function hello (call, callback) {
console.log(call.request.message)
}
server.addService(client.Hello.service, {hello: hello});
server.bind('localhost:50051', grpc.ServerCredentials.createInsecure());
server.start();
grpcClient = new client.Hello('localhost:50051',
grpc.credentials.createInsecure(),{deadline: new Date().getSeconds()+5}); //
grpcClient.hello({message: "abc"}, function(err, response) {
console.log(response) // doesn't reach here because function hello doesn't callback
})
Run Code Online (Sandbox Code Playgroud) 我有一个函数,我只想在第二次调用和第三次调用时模拟,但在第一次调用时使用默认实现。我查看了 Jest 文档,有一个函数 mockImplementationOnce 可以用来模拟单个调用的实现。
有没有我可以使用的函数,它会在第一次调用时使用默认实现,并且只模拟第二次和第三次调用?
let functionCalls = 0;
const database = {
fetchValues() {
fetchValues();
fetchValues();
},
};
jest.spyOn(database, 'fetchValues')
.useDefaultImplementation() // <-- is there such a function?
.mockImplementationOnce(() => 42)
.mockImplementationOnce(() => 42)
Run Code Online (Sandbox Code Playgroud) 我注意到在 ubuntu 中安装包时,生成的 package-lock.json 包含少数依赖包指向http://registry.npmjs.org而不是https://registry.npmjs.org,而大多数指向前往https://registry.npmjs.org。
我应该担心那些指向 http 而不是 https 的吗?我应该手动将它们更改为 https 吗?
你如何处理承诺之外的错误(例如下面的"新错误")?
function testError() {
throw new Error("new error") // how to handle this?
var p123 = new Promise(function(resolve, reject) {
resolve(123)
});
return p123
};
testError().catch(err => {
return err; // code doesn't come here
})
.then(ok => {
console.log(ok)
});
Run Code Online (Sandbox Code Playgroud) 以下括号后面跟一个大括号(例如({user}))有什么影响?
promise1.then(user => ({user}));
Run Code Online (Sandbox Code Playgroud) 有一个带有 url 形式的 react web 应用程序
http://localhost/user?id=123&name=SomeName&team=SomeTeam
是否有在 id、name 或 team 参数更改时触发的事件?
我知道有 componentWillReceiveProps 但它似乎只有在它是路由参数时才会触发,即
被更改而不是作为查询字符串参数
javascript ×6
node.js ×4
ecmascript-6 ×1
es6-promise ×1
grpc ×1
jestjs ×1
kubectl ×1
kubernetes ×1
mocking ×1
npm ×1
npm-install ×1
promise ×1
reactjs ×1
sinon ×1
typescript ×1