为什么Javascript的“atob()”和“btoa()”是这样命名的?
2022-08-29 23:30:15
在 Javascript 中,方法解码 base64 字符串,方法将 a 编码为 base64。window.atob()
window.btoa()
string
那么为什么他们没有被命名为像和? 并且没有意义,因为它们根本不是语义上的。base64Decode()
base64Encode()
atob()
btoa()
我想知道原因。
在 Javascript 中,方法解码 base64 字符串,方法将 a 编码为 base64。window.atob()
window.btoa()
string
那么为什么他们没有被命名为像和? 并且没有意义,因为它们根本不是语义上的。base64Decode()
base64Encode()
atob()
btoa()
我想知道原因。
和 方法允许作者将内容与 base64 编码相互转换。atob()
btoa()
在这些 API 中,出于助记符目的,可以将“b”视为“二进制”,将“a”表示“ASCII”。但是,在实践中,主要是由于历史原因,这些函数的输入和输出都是 Unicode 字符串。
我知道这已经很老了,但它最近出现在Twitter上,我想我会分享它,因为它是权威的。
我:
你@BrendanEich选择这些名字的?
他:
旧的Unix名称,很难找到手册页rn,但看到 https://www.unix.com/man-page/minix/1/btoa/....这些名称从Unix延续到Netscape代码库中。1995年,我匆匆忙忙地将它们反映在JS中(在五月的十天之后,但很快)。
如果 Minix 链接断开,下面是手册页内容:
BTOA(1) BTOA(1)
NAME
btoa - binary to ascii conversion
SYNOPSIS
btoa [-adhor] [infile] [outfile]
OPTIONS
-a Decode, rather than encode, the file
-d Extracts repair file from diagnosis file
-h Help menu is displayed giving the options
-o The obsolete algorithm is used for backward compatibility
-r Repair a damaged file
EXAMPLES
btoa <a.out >a.btoa # Convert a.out to ASCII
btoa -a <a.btoa >a.out
# Reverse the above
DESCRIPTION
Btoa is a filter that converts a binary file to ascii for transmission over a telephone
line. If two file names are provided, the first in used for input and the second for out-
put. If only one is provided, it is used as the input file. The program is a function-
ally similar alternative to uue/uud, but the encoding is completely different. Since both
of these are widely used, both have been provided with MINIX. The file is expanded about
25 percent in the process.
SEE ALSO
uue(1), uud(1).
来源:Brendan Eich,JavaScript 的创建者。https://twitter.com/BrendanEich/status/998618208725684224