1

there was a copy paste issue in some of our code the other day:

      ...
      if (form.isValid()) {
         scope: me, form.updateRecord(record);
         ...
      }
      ...

the strange thing is it did not actually register as a syntax error

the browser appears to have just ignored it

does anybody know what scope: me, actually does in this context? just curious

NOTE: this was tested in chrome. and the code is definitely being reached

chrisgotter
  • 383
  • 1
  • 3
  • 13
  • 3
    It's a statement label. – Pointy Dec 09 '19 at 20:58
  • a statement label? – chrisgotter Dec 09 '19 at 20:59
  • there are uncontrolled jumps in javascript? – chrisgotter Dec 09 '19 at 20:59
  • [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/label) - almost never used javascript feature. – ASDFGerte Dec 09 '19 at 20:59
  • They're rarely useful but it's a companion feature to `break` and `continue`. – Pointy Dec 09 '19 at 21:00
  • lol they ripped that syntax off from java – chrisgotter Dec 09 '19 at 21:00
  • Related [Javascript goto statement](https://stackoverflow.com/questions/14335353/javascript-goto-statement) – lurker Dec 09 '19 at 21:01
  • 2
    I don't think "ripped off from java" is correct. It's not like java invented any of this. – ASDFGerte Dec 09 '19 at 21:01
  • i mean using continue and break to reference labels and cutting out goto – chrisgotter Dec 09 '19 at 21:03
  • did somebody else do that first? – chrisgotter Dec 09 '19 at 21:03
  • i just assumed because i have seen this before (don't remember where) where super obscure features parallel java and i always suspected that they are relics from the time when they were just trying to capitalize on java's popularity like they did by naming the language "JavaScript" – chrisgotter Dec 09 '19 at 21:06
  • Well, even if that was the case (unlikely with the forest of languages and theories that existed even before java), it's like saying "there is this language feature that's almost always terribad, but anyone leaving it out ripped off from the first one who left it out". The "ripped off" is adding the wrong message here, as if it was some intellectual property that was copied. – ASDFGerte Dec 09 '19 at 21:09
  • i yield the point – chrisgotter Dec 09 '19 at 21:11
  • Dijkstra wrote `Goto considered harmful` in 1968, Java is about 30 years newer. Javascript isn't a superset of Java, although the name was used to imply it would be friendly enough for Java devs (which was a joke in practicality but the internets was a different place then). – Jared Farrish Dec 09 '19 at 21:11
  • i know that javascript is not a superset of java. it is an entirely different language however was it not named in such a way to capitalize on the popularity of java in web development at the time? – chrisgotter Dec 09 '19 at 21:14
  • so i don't think it is much of a stretch to say that when an obscure feature was developed which is identical in its unusual implementation to java is it unreasonable to say that it was at least "inspired" by java? – chrisgotter Dec 09 '19 at 21:16
  • I am unsure whether that's the case, but it may well be, that it was "inspired by java". – ASDFGerte Dec 09 '19 at 21:17
  • :) not trying to be divisive. it just feels like finding an Easter egg – chrisgotter Dec 09 '19 at 21:19
  • I'd say almost all questions i see on SO, that include a labeled statement, added it by accident, and their problem stems from the label. There are real uses for it, and i also have used it in code before, but it's rare. If you like "easter eggs", try `typeof document.all === "undefined" && document.all !== undefined`, in a browser environment. – ASDFGerte Dec 09 '19 at 21:24
  • I recall JavaScript was used to piggy back on the marketing for Java at the time. And that Scheme is much more important to JavaScript than Java. No idea what other languages had/used labeled breaks at the time, probably have to ask Eich why he included them to know. – Jared Farrish Dec 09 '19 at 21:31

0 Answers0