I am surprised that this generates an error:
var encode = (new TextEncoder()).encode;
encode("This is a test.");
The error message is TypeError: Illegal invocation
. I would think that this would be equivalent to
(new TextEncoder()).encode("This is a test.");
Aside from assigning the method to a variable and then invoking it using the name of the variable I assigned it to, I mean, I would think that they're equivalent. Why do I need to go through the trouble of creating a new TextEncoder
object, assigning it an identifier, and then calling encode
from that identifier?