javascript 错误:无法访问词法声明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31068665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 13:12:36  来源:igfitidea点击:

Error: Can't access lexical declaration

javascriptfirefox-addonjsctypesnss

提问by Nona Haron

let textBytes = ctypes.uint8_t("hello"); 
let a = new SECItem;
a.type = siBuffer;
a.data = textBytes.address();
a.len = textBytes.length;

I got ReferenceError: can't access lexical declaration textBytes before initialization.

我得到了 ReferenceError: can't access lexical Declaration textBytes before Initialization。

回答by Noitidart

I can't reproduce the reference error you are getting, but I think change

我无法重现你得到的参考错误,但我认为改变

let textBytes = ctypes.uint8_t("hello"); 

as this throws TypeError: expected type uint8_t, got "hello"to

因为这将引发TypeError: expected type uint8_t, got "hello"

let textBytes = ctypes.uint8_t.array()("hello"); 

This will give you a null-terminated string, of length 6. If you want it to be length 5, no null termination then do let textBytes = ctypes.uint8_t.array(5)("hello");

这将为您提供一个长度为 6 的空终止字符串。如果您希望它的长度为 5,则没有空终止然后执行 let textBytes = ctypes.uint8_t.array(5)("hello");

as I am thinking, change

正如我所想,改变

let a = new SECItem;

to

let a = SECItem();

or let a = new SECItem();they are both same.

或者let a = new SECItem();他们都是一样的。

If that doesn't fix it, please share the structure of SECItemand what is siBuffer.

如果不解决这个问题,请分享的结构SECItem,什么是siBuffer