Object built-in object

objectTextEncoder

TextEncoder encoding object

Creation method

1
var textEncoder = new util.TextEncoder('utf8');

inheritance relationship

Constructor

TextEncoder

TextEncoder object constructor, constructed with parameters

1 2
new TextEncoder(String codec = "utf8", Object opts = {});

Call parameters:

  • codec: String, specifies the coded character set
  • opts: Object, specifies encoding options

member attribute

encoding

String, query the current coded character set

1
readonly String TextEncoder.encoding;

member function

encode

Convert text to binary data

1 2
Buffer TextEncoder.encode(String data = "", Object opts = {});

Call parameters:

  • data: String, the text to convert
  • opts: Object, specifies encoding options

return result:

  • Buffer, returns encoded binary data

toString

Return the string representation of the object, generally return "[Native Object]", the object can be reimplemented according to its own characteristics

1
String TextEncoder.toString();

return result:

  • String, returns a string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable properties defined by the object

1
Value TextEncoder.toJSON(String key = "");

Call parameters:

  • key: String, not used

return result:

  • Value, which returns a JSON-serializable value