Another Bug with objects in "For Each"


#1

This is the code:

Sub Button3_onclick()
  Dim myCar 
  Dim i
  myCar = new Car("Ford", "Mustang", 1969)
  
'This should work, but it doesn't!
  'For Each i in myCar 
  
'But this works:
  JavaScript
  for (i in myCar) {
  End JavaScript
 
    If myCar.hasOwnProperty(i) Then
      Print i & ": " & myCar[i]
    End If
  Next i  
End Sub

As you can see: In my code does this lines work:

JavaScript
  for (i in myCar) {
End JavaScript

but

For Each i in myCar

doesn’t! and now it becomes weird: If I delete
If myCar.hasOwnProperty(i) Then
and
End If
then it works even with
For Each i in myCar

Here is a project to test both bugs:
BugObj.nsx (21.1 KB)


#2

The Translator has known problems converting some forms of For Each. The JavaScript equivalent is close, but not the same. It does its best, but there are some cases in which it does not work.