Question about Java script
All  1  2-3

Previous
Next
 From:  Michael Gibson
12056.2 In reply to 12056.1 
Hi Frederick,

re:
> Is this because the file list does not support the form as used for the
> directory list - for (var d in dirlist)?

Yes, here the dirlist variable is a native JavaScript Array that was created by the JavaScript runtime.

The files variable is a MoiList object created by Moi,

Until recently in v5 objects that were created by Moi did not support the for ( propname in object ) syntax.

Since v5 Mar-29-2023, the for ( propname in object ) syntax is now supported on objects created by MoI but it doesn't have the special behavior for JavaScript arrays.

It's generally considered a best practice to use a regular for () loop with an index variable to loop through the contents of an array and not for ... in .

Some info here:
https://stackoverflow.com/questions/5263847/javascript-loops-for-in-vs-for
https://www.geeksforgeeks.org/javascript/why-using-for-in-for-array-iteration-a-bad-idea-in-javascript/

- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  fcwilt
12056.3 In reply to 12056.2 
Hi Michael,

Interesting.

So it doesn't work anything like the 'for in" I use in Delphi. There the programmer gets to/has to code the class enumerator and thus "for in" can do exactly what he wants it to.

Over the years I am often bemused at some of the things that Java and JavaScript do.

Thanks for the references as well.

Frederick
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All

 

 
 
Show messages: All  1  2-3