请问在JS中可以用什么代码代替AS3中的writeUTFBytes、writeInt与position命令?

spaceplan9 2017-02-02 05:08:46
比如像AS3中这样的代码:
public static function hash(_arg1:String):String{
var _local2:ByteArray = new ByteArray();
_local2.writeUTFBytes(_arg1);
return (hashBinary(_local2));
}

digest = new ByteArray();
digest.writeInt(_local2);
digest.writeInt(_local3);
digest.writeInt(_local4);
digest.writeInt(_local5);
digest.position = 0;

这些代码里面的writeUTFBytes、writeInt与position在JS中用什么命令表示?
...全文
356 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fc9625 2017-06-23
  • 打赏
  • 举报
回复
// js代码 function string2ByteArray(str) { let bytes = [] for (let i = 0; i < str.length; i++) { const code = str.charCodeAt(i) bytes = bytes.concat([code]) } return bytes } // as代码 public static function convertStringToByteArray(str:String):ByteArray { var bytes:ByteArray; if (str) { bytes=new ByteArray(); bytes.writeUTFBytes(str); } ​return bytes; } 上面俩代码返回结果相同。
似梦飞花 2017-02-02
  • 打赏
  • 举报
回复
Int8Array es6试试是不是你要的

87,908

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧