views:

77

answers:

2

Going thru the excellent Apress books on Objective C. To help in my undertanding, I try and recode any Ojective C code samples in Java/Action-script. One common structure in method calls in ObjC leaves me a bit puzzled.

-(id) initWithPressure: (float) pressure
      treadDepth: (float) treadDepth;

(in ECMAscript)Would this be most similar to 1 method call with multiple arguments OR 2 method calls, each with a single argument?

+4  A: 

That's a single method call with two arguments; probably something like:

function initWithPressureAndTreadDepth(float pressure, float treadDepth);
Dave DeLong
A: 

I think a parameter object with named fields is a good substitute for the Objective-C concept.

function initWith(arg)
{
    if(arg.pressure < 10.0)
    {
      ...
    }
}
initWith({pressure: pressure, treadDepth: treadDepth}); 
Matthew Flaschen
Initialization objects are better due to their flexibility, thought it does not equate very well to Objective-C as the ordering does not matter in the above Javascript example, and the parameters are not guaranteed to be there in the init function unlike in the Objective-C example.
Anurag