delete ax object and JSLint

A

Andrew Poulos

With this

var ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
//... blah
delete ax;

JSLint complains that

Problem at line 3 character 10: Expected '.' and instead saw ';'.


What's the '.' that JSLint is expecting?

Andrew Poulos
 
M

Martin Honnen

Andrew said:
With this

var ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
//... blah
delete ax;

JSLint complains that

Problem at line 3 character 10: Expected '.' and instead saw ';'.


What's the '.' that JSLint is expecting?

Ask in http://tech.groups.yahoo.com/group/jslint_com/.

I suppose it only wants you to delete properties of ax, as in

var ax = { foo: 'bar' };
//... blah
delete ax.foo;
 
T

Thomas 'PointedEars' Lahn

Andrew said:
With this

var ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
//... blah
delete ax;

JSLint complains that

Problem at line 3 character 10: Expected '.' and instead saw ';'.

What's the '.' that JSLint is expecting?

As Martin said. In addition, your `delete' statement is pointless. `ax'
has been declared a variable, a property of the Variable Object of the
execution context with the DontDelete attribute, and you can only `delete'
properties without the DontDelete attribute. See the ECMAScript Language
Specification, Edition 3 Final, section 11.4.1.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Conrad said:
[...] It's also legal to delete undeclared "variables" (actually
properties):

x = 2;
delete x;

However, the first line is error-prone, so the second line should be rare.


PointedEars
 
M

Martin Honnen

Conrad said:
Which would be correct, because variables can't be deleted.

According to the spec, yes, although it does not forbid trying to do
that, only such attempts are supposed to fail. And with JScript it does
not fail (and ActiveXObject suggests the original poster is using JScript).
 
T

Thomas 'PointedEars' Lahn

Martin said:
According to the spec, yes, although it does not forbid trying to do
that, only such attempts are supposed to fail. And with JScript it does
not fail (and ActiveXObject suggests the original poster is using JScript).

If the `delete' operation does not fail with variables that would certainly
be a bug waiting to be fixed. Anyhow, in JScript 5.6.6626 (in Standalone IE
6.0.2800.1106) it fails, and rightly so:

var x = "foo";

/* false */
window.alert(delete x);

/* string */
window.alert(typeof x);

/* "foo", no RuntimeError */
window.alert(x);

<http://msdn.microsoft.com/en-us/library/as11h77s(VS.71).aspx>


PointedEars
 
M

Martin Honnen

Thomas said:
If the `delete' operation does not fail with variables that would certainly
be a bug waiting to be fixed. Anyhow, in JScript 5.6.6626 (in Standalone IE
6.0.2800.1106) it fails,

You are right, it fails, sorry for the wrong claim. The test I did
evaled the code and that way I got a different result as in the context
of "eval code" variables can be deleted (ECMAScript edition 3 10.2.2:
"Variable instantiation is performed ... using empty property attributes.").
 
J

JR

var ax = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
//... blah
delete ax;

JSLint complains that

I've seen *delete* being used thusly around Internet, when the correct
assignment should be:

ax = null;

Cheers,
Joao Rodrigues
 
A

Andrew Poulos

JR said:
I've seen *delete* being used thusly around Internet, when the correct
assignment should be:

ax = null;

Thanks to everyone who helped. I went back over the documentation on
Mozilla and realised that I misread

delete variableName

as meaning I can delete *any* variable. Its obvious now that
variableName must evaluate to a property (mainly because its clearly
stated in the Mozilla docs.)

Andrew Poulos
 
D

David Mark

Which would be correct, because variables can't be deleted. The wording
of the error message is unexpected - it would be syntactically valid to
do this, for example:
  var bla = {x: 1, y: 2};
  with (bla) {
      delete x;    // no "." or "[]" required here
  }
But JSLint already bails at |with|: "Expected an identifier and instead
saw 'with'." It's also legal to delete undeclared "variables" (actually
properties):
  x = 2;
  delete x;
Same "Expected '.'" error message here.
JSLint error messages sometimes... require a little imagination. It
helps to remember that JSLint is not a syntax checker; it only checks
against a subset of so-called "Good Parts" of JavaScript.

I also noticed JSLint being intolerant to an innocent `void` operator:

(void 0);

produces:

"Problem at line 1 character 2: Expected an identifier and instead saw
'void'."

I have no idea what's up with that.

Or why - window - is suddenly an "implied global", even when assuming
a browser. It's got some odd quirks for sure. I just ignore them
though as it is an excellent tool overall.
 
J

JR

I also noticed JSLint being intolerant to an innocent `void` operator:

(void 0);

produces:

"Problem at line 1 character 2: Expected an identifier and instead saw
'void'."

I have no idea what's up with that.

Just quoting Douglas Crockford (http://www.jslint.com/lint.html):

"Void
In most C-like languages, void is a type. In JavaScript, void is a
prefix operator that always returns undefined. JSLint does not expect
to see void because it is confusing and not very useful."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top