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
    }
  }

更多 HarmonyOS Next学习:

HarmonyOS Next

配套课件及源码下载地址:HarmonyOS HarmonyOS Next系列教程下载地址-IT营大地老师

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值