Question about Java script

Next
 From:  fcwilt
12056.1 
Hi,

I noticed this is a file ScriptsFull.menu.htm:

for (var d in dirList)
{
var files = moi.filesystem.getFiles(dirList[d], '*.js' );
for ( var i = 0; i < files.length; ++i )
{
// some more stuff was here
}
}


The files are accessed using a for loop and an index variable.

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

Thanks.

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

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
Next
 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

Previous
Next
 From:  wayne hill (WAYNEHILL5202)
12056.4 
Use JavaScript version ES5 if generating code for MoI3d from AI.

Wayne
  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
Next
 From:  fcwilt
12056.5 In reply to 12056.4 
Hi Wayne.

So AI can generate code?

How does it know what to do?

Thanks.

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

Previous
 From:  Frenchy Pilou (PILOU)
12056.6 In reply to 12056.5 
Of course Ai can generate code about anything! :)
But you must manage it with some Q&R! :)
Send an image or/ and text who explain that you want in any domains!
I have absolutely no knowledge ot the five or more languages used! (Htlml, Css, render, JavaScript etc...

Here a little headache for play with it! :) Just fill the screen with same form who can be Rotated or Mirrored! ;)
Free Claude was used ... it can of course gives the answer but better oneself to seach by pleasure!
https://moiscript.weebly.com/jeux.html

EDITED: 11 Aug by PILOU

  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