harmonyos next 提示'Function.apply', 'Function.call' are not supported (arkts-no-func-apply-call)
harmonyos next 提示’Function.apply’, ‘Function.call’ are not supported (arkts-no-func-apply-call)
Calls the function, substituting the specified object for the this value of the function, and the specified array for the arguments of the function.
报错信息提示’Function.apply’, ‘Function.call’ 在 harmonyos next 中不被支持,这通常意味着你正在尝试使用在当前版本的 harmonyos 中不被允许的 JavaScript 功能。
Function.apply 和 Function.call 是 JavaScript 中的两个方法,它们被用来在特定的作用域中调用函数。在某些 JavaScript 环境中,比如某些小程序框架(如 arkt),可能会有特定的限制,导致这两个方法无法使用。 harmonyos next 解决方法
let data=new Uint8Array(buf.slice(0, readLen))
//把buf转换成string
this.message = "read data succeed--" + String.fromCharCode(...data)
完整代码
//读取文件 打开文件流
fsReadFile() {
//注意:要手动抛出异常
try {
let context: Context = getContext(this) as Context
let filePath = context.filesDir + "/text.txt";
//以流的方式读取
let ss = fs.createStreamSync(filePath, "r+");
//申请空间
let buf = new ArrayBuffer(4096)
//读取的数据放在buf里面
ss.read(buf, (err, readLen) => {
if (err) {
this.message = "read stream failed with error message: " + err.message + ", error code: " + err.code
} else {
let data=new Uint8Array(buf.slice(0, readLen))
//把buf转换成string
this.message = "read data succeed--" + String.fromCharCode(...data)
}
});
} catch (e) {
this.message = "read data Error" + e
}
}