1

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?

Shog9
  • 156,901
  • 35
  • 231
  • 235
Bachalo
  • 6,965
  • 27
  • 95
  • 189

2 Answers2

4

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

function initWithPressureAndTreadDepth(float pressure, float treadDepth);
Dave DeLong
  • 242,470
  • 58
  • 448
  • 498
0

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
  • 278,309
  • 50
  • 514
  • 539
  • 1
    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 May 09 '10 at 00:20