Misspelling Can Bite You

Discussion in 'Javascript' started by Gene Wirchenko, Feb 2, 2012.

  1. Dear JavaScripters:

    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
    switch (this.DateType)
    when it should have been
    switch (this.DataType)

    JavaScript was quite happy to execute the code. After all, the
    switch might have had a case to handle undefined.


    Gene Wirchenko
    Gene Wirchenko, Feb 2, 2012
    1. Advertisements

  2. IE 9.
    Huh? The sequence was syntactically correct. The only problem
    with it was a misspelling of a property name. That corrected, the
    code ran fine.
    I described the result of misspelling a property name, not a



    Gene Wirchenko
    Gene Wirchenko, Feb 3, 2012
    1. Advertisements

  3. JavaScript may not even have been used.
    There is not *the* language with regard to browsers, unless you consider
    "JavaScript" to be a stand-in for "ECMAScript (implementations)", which is
    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(", ") + ")");


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


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

    Thomas 'PointedEars' Lahn, Feb 3, 2012
  4. In comp.lang.javascript message <[email protected]

    Putting the following script element last, or making it a body onload
    function, will list all the script words of more than 2 letters, in
    alphabetical order, with the number of times used. The result will be
    browser-dependent; but not gravely so. Demo in my js-misc1.htm.

    <script type="text/javascript">

    var skripts = document.getElementsByTagName("SCRIPT")
    var L = skripts.length, Str = "", Out = []
    while (L--) Str += skripts[L].innerHTML
    Str = Str.split(/\W+/).sort()
    var was = "", K = 0
    L = Str.length
    while (L--) {
    if (Str[L] == was) K++ ; else {
    if (was.length > 2 && /^[a-z]/i.test(was)) Out.push(K + " " + was)
    K = 1 ; was = Str[L] } }
    document.write("<pre>" + Out.reverse().join("\n") + "<\/pre>")


    The code could, no doubt, be optimised. The output might better be to a
    textarea or a new page. It could be well to NOT scan words in strings
    or comment.

    Code could be added to pick out cases where two adjacent words are
    unreasonably similar.
    Dr J R Stockton, Feb 3, 2012
  5. Gene Wirchenko

    Mel Smith Guest

    Dr. J said:

    Dr J and Gene:

    This morning I was caught (and mislead) by the following set of two

    var rgn = document.getElementById("iselectrgn") ;
    var rgnopts = rgn.getElementsByTagname("option") ;

    Because I *thought* I had checked the statements thoroughly, I looked
    everywhere *after* this set, and finally went back and checked them again
    letter-by-letter, and then ...

    -Mel Smith
    Mel Smith, Feb 4, 2012
  6. Readily found by Firefox/Opera/Safari Error Console, Chrome JavaScript
    Console, and by an IE8 pop-up, though.
    Dr J R Stockton, Feb 5, 2012
  7. Gene Wirchenko

    Mel Smith Guest

    Dr. J said:
    Yes, I use IE 7 on my dev machine, and 'once-in-a-while' (when I'm
    nearing the production stage) I check out the appearance on Chrome and FF.

    However, I didn't *this* time and spent a couple of confusing and
    frustrating hours tracking down this 'devil'.

    -Mel Smith
    Mel Smith, Feb 6, 2012
  8. One fault with those Error Consoles is that they lack a "Stay On Top"
    checkbox, or one for "Jump up when written to".

    Re my earlier code : given a reference to a script element, one can get
    ..innerHTML and (in all my browsers) read as a string the script as
    transmitted. Is there any easy way of getting that string, MINUS all
    comment and MINUS all inner strings (or, in each case, removing the
    content of the comments and strings) while leaving all the other code?
    Dr J R Stockton, Feb 7, 2012
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.