Javascript atob、btoa 为什么要这么命名

阅读(764)

atob() 和 btoa() 函数用于 base64 编码与解码,但是命名的简单导致容易记错。

In these APIs, for mnemonic purposes, the "b" can be considered to
stand for "binary", and the "a" for "ASCII". In practice, though, for
primarily historical reasons, both the input and output of these
functions are Unicode strings.
via w3: https://www.w3.org/TR/html/webappapis.html#base64-utility-methods

这样就好理解了:

  • a:Ascii,即 Base64 编码的展现形式
  • b:Binary,除 Base64 编码以外的形式

“a”指的是 base64,“b”不是指base64

  • atob:Base64 decode
  • btoa:Base64 encode

Refer:
https://stackoverflow.com/questions/33854103/why-were-javascript-atob-and-btoa-named-like-that

Tags: base64