Go Back   SmartClient Forums > Technical Q&A
Wiki Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 13th Feb 2007, 12:13
tgochenour tgochenour is offline
Registered Developer
 
Join Date: Jan 2007
Posts: 135
Default DynamicForm.isA("class")

I have an array of widgets containing DynamicForms and ListGrids.

I do a for( var widget in widgetsArray )
and my first "widget" is the field "class" with a value of "Array". I pass this to DynamicForm.isA() and it returns TRUE. It's a string, not a form.

----

While this is still true, my usage was wrong. widget is always a string. Now I'm calling DynamicForm.isA(widgetsArray[widget]) and the isA function returns false for the string "Array". I guess it's returning true for the string "class".

Last edited by tgochenour; 13th Feb 2007 at 12:22..
Reply With Quote
  #2  
Old 13th Feb 2007, 13:46
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 30,581
Default

isc.DynamicForm.isA("Class") with uppercase "Class" is true and should be true, since DynamicForm extends the base class "Class".

But your original problem is that you should not be doing for..in iteration on Arrays; for..in iteration should be only be used with Objects This is because many frameworks add properties and methods to the global Array object that you will hit if you use for..in iteration. Instead, use classic iteration:

Code:
for (var i = 0; i < widgetsArray.length; i++) {
    var widget = widgetsArray[i];
}
Classic iteration is a recommended best practice that emerging AJAX standards bodies have agreed on, and it's also nearly an order of magnitude faster on some browsers.
Reply With Quote
  #3  
Old 13th Feb 2007, 14:53
tgochenour tgochenour is offline
Registered Developer
 
Join Date: Jan 2007
Posts: 135
Default

Right. Thing about Javascript is that an Array and an Object are the same thing. My usage is with an Object taking the form of a HashMap and instantiated with "widgetArray = []". I don't have a numerical array to use the classic iterator on. I have a HashMap where the field names are keys and the field values are the references.

That's why I'm using "for widget in widgetArray".

Anyway, DynamicForm.isA("Class") returns TRUE because a form extends Class, even though the string "Class" isn't a DynamicForm?

OK. My usage was wrong anyway. Now that I'm using widgetArray[widget] the isA function skips over the Class="Array" attribute just fine.
Reply With Quote
  #4  
Old 13th Feb 2007, 14:59
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 30,581
Default

In JavaScript, all Arrays are Objects but not all Objects are Arrays. When you want something comparable to a Java HashMap, use "widgetMap = {}" (note curly braces), which creates an Object rather than an Array. With an Object, for..in iteration will reveal only the properties you set.

isc.DynamicForm.isA() takes a className, and is an API oriented toward introspection of the class hierarchy. You may be confusing it with isc.isA.DynamicForm(), which is used for detecting DynamicForm instances.
Reply With Quote
  #5  
Old 13th Feb 2007, 15:17
tgochenour tgochenour is offline
Registered Developer
 
Join Date: Jan 2007
Posts: 135
Default

isc.isA.DynamicForm() is not present in the documentation at http://www.smartclient.com/docs/5.5....ml#object..isA

This is why I'm using the isc.DynamicForm.isA() variety.
Reply With Quote
  #6  
Old 13th Feb 2007, 15:21
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 30,581
Default

From that doc:

Quote:
An isA method is automatically created for every ISC Class and Interface definition, for example, isA.Canvas().
Is there a way we could word that better so that it's clear that isc.isA.DynamicForm() exists?
Reply With Quote
  #7  
Old 13th Feb 2007, 15:55
tgochenour tgochenour is offline
Registered Developer
 
Join Date: Jan 2007
Posts: 135
Default

I wasn't reading the overview. I was looking at the Class APIs.

My bad.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


© 2010,2011 Isomorphic Software. All Rights Reserved