比如像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中用什么命令表示?

解决方案 »

  1.   

    Int8Array es6试试是不是你要的
      

  2.   

    // 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;
    }
    上面俩代码返回结果相同。