可以使用哪种机制来访问与JavaScript关键字冲突的Java方法?

时间:2022-01-29 17:02:41

I've a Javascript source that uses a Java class that defines a "delete" method (using jdk6 scripting). Since delete is a keyword, I cannot invoke that method.

我有一个Javascript源代码,它使用定义“删除”方法的Java类(使用jdk6脚本)。由于delete是一个关键字,我无法调用该方法。

In JavaFX script any sequence of characters enclosed in <> is treated as a lexical identifier. So you can use "insert", that is a keyword, as an identifier:

在JavaFX脚本中,<>中包含的任何字符序列都被视为词法标识符。因此,您可以使用“insert”(即关键字)作为标识符:

var textField = new javax.swing.JTextField();
textField.<<insert>>("Hello World");

Javascript provides a way to protect keywords?

Javascript提供了保护关键字的方法吗?

1 个解决方案

#1


In javascript you would do:

在javascript中你会做:

textField["insert"]("Hello World");

#1


In javascript you would do:

在javascript中你会做:

textField["insert"]("Hello World");