2 Replies Latest reply on Sep 19, 2016 8:39 AM by K.Daube

    Invalid property does not create an error

    K.Daube Level 2

      Dear experts,
      In a script inserting a marker I had a typo on line 08:

      function InsertMarker (oTtextRange, sMarkerName, sMarkerText ) {
      var j, textLoc, marker, markerType, thisId, thatId, lenMarkerArray;
        textLoc = oTtextRange.end;                      // inserted at end of selection
        markerType = GetMarkerType (goCurrentDoc, sMarkerName); // Get the specified marker type.    
        if (markerType.ObjectValid ()) {  
            marker = goCurrentDoc.NewAnchoredMarker (textLoc);  
            marker.MarkerTypeId = markerType;           // properties of marker
            marker.sMarkerText = sMarkerText;  
            thisId = marker.Unique;                     // to find it in the updated array
      // ...

      Line 08 should read:

      marker.MarkerText = sMarkerText;

      Hence the marker was inserted with empty content.

      It seems that an invalid property is just ignored. Are there no checks for invalid properties?



        • 1. Re: Invalid property does not create an error
          4everJang Level 3

          Hello Klaus,


          JavaScript has no invalid properties when you are writing a value. Properties are simply names in a lookup table. Misspelling a property to write to causes a new property with that name to be added to the list. And of course you already know that everything in JavaScript is case-sensitive. In your code, The "sMarkerText' property you wrote to was not ignored but simply added to the 'marker' object.


          This is a very powerful feature (which I have succesfully used on many occasions to let my own data travel with the object even when calling standard methods on the objects). But it can also be the cause for much debugging work when you are not absolutely rigid in your naming schemes.


          If you do not have autocompletion switched on in your ESTK, I would strongly suggest doing so. It only works on one level and is not perfect (not all properties are always shown), but at least you will know to double-check the property name if there is no suggestion at all while you are typing.


          Good luck

          1 person found this helpful
          • 2. Re: Invalid property does not create an error
            K.Daube Level 2

            Thank You , Jang

            You know, I'm still learning and with another typo I discovered that there is a comma operator!

            Ever heard of this?

            IMHO this is an obfuscation of code - only for beginners?

            (see https://javascriptweblog.wordpress.com/2011/04/04/the-javascript-comma-operator/).