gpt4 book ai didi

javascript - 在使用 .map 调用的 JavaScript 类函数中使用 'this'

转载 作者:行者123 更新时间:2023-11-30 08:28:39 24 4
gpt4 key购买 nike

<分区>

我有以下类(class):

class RegisterUser {
constructor(username, password, ispublic){
this.username = username;
this.password = password;
this.ispublic = ispublic;
this.identity = crypto.signKey();
this.preKeys = [];
if (ispublic){
this.preKeys = crypto.getPreKeys(10);
}
}
get data(){
return {
identity_key: this.identity.publicKey,
username: this.username,
usernameSignature: this.usernameSignature,
signedPreKeys: this.signedPreKeys,
ispublic: this.ispublic
}
}
get usernameSignature(){
return this.identity.sign(buf(this.username, 'utf8'));
}
signPreKey(key){
var publicKey = key.publicKey;
var signature = this.identity.sign(pub);
return {
publicKey: publicKey,
signature: signature
}
}
get signedPreKeys(){
var signFunc = this.signPreKey;
return this.preKeys ? this.preKeys.map(signFunc) : null;
}
get encryptedIdentity(){
var cipher = ncrypto.createCipher('aes192', this.password);
var encrypted = new Buffer(cipher.update(this.identity.secretKey));
return Buffer.concat([encrypted, new Buffer(cipher.final())]);
}
}

.data() 在这个类的一个新实例化的实例上被调用时,我得到:

Cannot read property 'identity' of undefined" in the signPreKey function.

有没有一种方法可以在不替换 this 的情况下使用 .map

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com