Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #11174

Re: Misspelling Can Bite You

Message-ID <1344140.x7N3WIZj58@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2012-02-03 04:15 +0100
Subject Re: Misspelling Can Bite You
Newsgroups comp.lang.javascript
References <po1mi75fb0u5rqp9or413nv26799lpnndj@4ax.com> <NcednWLYUtTEp7bSnZ2dnUVZ8hqdnZ2d@giganews.com>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


Richard Cornford wrote:

> Gene Wirchenko wrote:
>>     Once again, it is time to thank me for pointing a possible
>> source of errors in JavaScript code or to chuckle over how I
>> messed up again, maybe both.
>>
>>     I misspelled the name of the control variable for a switch.
>>  I had
>>          switch (this.DateType)
>> when it should have been
>>          switch (this.DataType)
>>
>>     JavaScript was quite happy to execute the code.

JavaScript may not even have been used.

>>     After all,
>> the switch might have had a case to handle undefined.
> 
> Really? Which browser, because the language's syntax won't stand for a -

There is not *the* language with regard to browsers, unless you consider 
"JavaScript" to be a stand-in for "ECMAScript (implementations)", which is 
wrong.

> case - clause inside a Block statement (and a - switch - isn't much use
> without at least one - case - clause), so there should have been a
> syntax error to prevent compilation, and so prevent any execution.

I think he meant

  switch (this.bar)
  {
    case undefined:
      …
  }

where the object referred to by `this' had a `foo' property instead.  Only 
that in this case `foo' and `bar' were much more similar.

Barring `this' referring to a host object or `bar' being a specially 
designed accessor property¹, any conforming implementation of ECMAScript Ed. 
1 to 5.1 would execute that code without throwing an exception, with or 
without the `case undefined' clause, because you can attempt to access any 
property of the object referred to by `this' or the object converted from 
the value of `this' (ES 5.x strict mode) without it throwing an exception.  
Accessing a non-existing property merely results in `undefined'.  (I am 
presently not aware of any feature in ES 5.1 that would change that 
behavior.  Strict mode is not it.  SpiderMonkey's __noSuchMethod__ property² 
only allows it for method calls.  ES Harmony is going to allow it with 
dynamic proxies, but not on regular objects.³)

¹ Object.defineProperty(this, "bar", {
    get: function () {
      throw new TypeError();
    }
  });

² this.__noSuchMethod__ = function (id, args) {
    throw new Error(id + "(" + args.join(", ") + ")");
  };

  this.bar();

³ var o = Proxy.create({
    get: function (rcvr, name) {
      if (name == "bar")
      {
        throw new TypeError();
      }
    }
  }, this);

  o.bar;

  See also 
<http://www.youtube.com/watch?v=A1R8KGKkDjU&feature=plcp&context=C38a9548UDOEgsToPDskJEdhctNqhQUmYwp-
S69WbK>
   
> However, the situation you describe, of mistyping a keyword and still
> having code execute is a possibility. One example would be mistyping -
> if - to give:-
> 
> id(x)
> {
>   y = 12;
> }
> 
> - which would produce a runtime error, "id is not a function", rather
> than a syntax error.
> […]

While this is valuable information indeed, I think you have misunderstood 
the OP.


PointedEars
-- 
Sometimes, what you learn is wrong. If those wrong ideas are close to the 
root of the knowledge tree you build on a particular subject, pruning the 
bad branches can sometimes cause the whole tree to collapse.
  -- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom@94.75.214.39>

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Misspelling Can Bite You Gene Wirchenko <genew@ocis.net> - 2012-02-02 14:02 -0800
  Re: Misspelling Can Bite You "Richard Cornford" <Richard@litotes.demon.co.uk> - 2012-02-03 01:37 +0000
    Re: Misspelling Can Bite You Gene Wirchenko <genew@ocis.net> - 2012-02-02 18:09 -0800
    Re: Misspelling Can Bite You Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-03 04:15 +0100
  Re: Misspelling Can Bite You Dr J R Stockton <reply1205@merlyn.demon.co.uk> - 2012-02-03 22:49 +0000
    Re: Misspelling Can Bite You "Mel Smith" <med_cutout_syntel@aol.com> - 2012-02-04 13:21 -0700
      Re: Misspelling Can Bite You Dr J R Stockton <reply1205@merlyn.demon.co.uk> - 2012-02-05 16:59 +0000
        Re: Misspelling Can Bite You "Mel Smith" <med_cutout_syntel@aol.com> - 2012-02-06 10:28 -0700
          Re: Misspelling Can Bite You Dr J R Stockton <reply1206@merlyn.demon.co.uk> - 2012-02-07 21:54 +0000

csiph-web