TextDecoder()
The TextDecoder()
constructor returns a newly created
TextDecoder
object for the encoding specified in parameter.
If the value for utfLabel is unknown, or is one of the two values leading to a
'replacement'
decoding algorithm ( "iso-2022-cn
" or
"iso-2022-cn-ext
"), a DOMException
with the
"TypeError"
value is thrown.
Syntax
decoder = new TextDecoder(utfLabel, options);
Parameters
utfLabel
Optional- Is a
DOMString
, defaulting to"utf-8"
, containing the label of the encoder. This may be any valid label. options
Optional- Is a
TextDecoderOptions
dictionary with the property:fatal
- A
Boolean
flag indicating if theTextDecoder.decode()
method must throw aDOMException
with the"EncodingError"
value when an coding error is found. It defaults tofalse
.
Example
var textDecoder1 = new TextDecoder("iso-8859-2");
var textDecoder2 = new TextDecoder();
var textDecoder3 = new TextDecoder("csiso2022kr", {fatal: true}); // Allows EncodingError exception to be thrown.
var textDecoder4 = new TextDecoder("iso-2022-cn"); // Throw a TypeError exception.
Specifications
Specification | Status | Comment |
---|---|---|
Encoding The definition of 'TextDecoder()' in that specification. |
Living Standard | Initial definition. |
Browser compatibility
BCD tables only load in the browser
See also
- The
TextDecoder
interface it belongs to.