• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Invalid property does not create an error

Community Expert ,
Sep 16, 2016 Sep 16, 2016

Copy link to clipboard

Copied

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?

Klaus

TOPICS
Scripting

Views

265

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Sep 16, 2016 Sep 16, 2016

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

...

Votes

Translate

Translate
Advocate ,
Sep 16, 2016 Sep 16, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2016 Sep 19, 2016

Copy link to clipboard

Copied

LATEST

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/).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines