Yeah, I thought there was a 'validJavascriptID' predicate or
something. It should barf if you try to use a keyword. (And
apologize for Javascript having so many keywords!)
On 2009-09-25, at 08:20, Henry Minsky wrote:
We should warn when the user uses a reserved name for a method name or
attribute.
There used to be some test cases in test/compiler_errors, although I
don't
know if
we have a test for using reserved words. I'll see if we can automate
some of those tests and add them to our test lztest suite.
On Fri, Sep 25, 2009 at 5:12 AM, Max Carlson <[email protected]>
wrote:
Should the compiler want when methods/attributes are named after
keywords/reserved words?
P T Withington wrote:
`delete` is a keyword in Javascript. You can't use it as an
identifier.
Without knowing what you are doing in "..." I can't say more.
Rhino 1.6 release 5 2006 11 18
js> var foo = {'delete': 42}
js> foo.delete
js: "<stdin>", line 3: missing name after . operator
js: foo.delete
js: .........^
js: "<stdin>", line 3: Compilation produced 1 syntax errors.
js> foo['delete']
42
js>
Accidentally, you _can_ say `foo.delete` to the OL debugger and
get an
answer, because the debugger's simple evaluator does not know that
`delete`
is a keyword.
[Also note, in general, you will not be able to enumerate the
methods of a
class by looking at the properties of an instance. Yes, that's
the way it
is implemented (for now) in DHTML, but your code will not be
portable to
swf9, and I expect Javascript "Harmony" will have a class-like
feature that
will also make your code non-portable.]
On 2009-09-23, at 10:49, Rami Ojares / AMG Oy wrote:
Hi,
Does anyone know why a method with name delete is ignored?
I have a class with a method named delete:
<class ...>
<method name="delete">
...
</method>
</class>
When I go through it's attributes using:
for (var name in instanceOfClass) ...
the object does not contain function with that name
But when I change the name to say delete1 then everything works as
expected.
Strange?
...
Thinking for a while before sending I came to the conclusion that
it must
be because there exists a delete operator in javascript.
So delete can not be a variable name because it is a reserved word.
Compiler warning would be great in these kind of situations.
- rami
--
Regards,
Max Carlson
OpenLaszlo.org
--
Henry Minsky
Software Architect
[email protected]