从Objective C到ECMAscript

时间:2010-05-08 17:28:03

标签: javascript objective-c actionscript-3 ecma262

通过关于Objective C的优秀Apress书籍。 为了帮助我完成工作,我尝试用Java / Action-script重新编码任何Ojective C代码示例。 ObjC中方法调用中的一个常见结构让我有些困惑。

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

(在ECMAscript中)这是否与1个方法调用最相似,多个参数或2个方法调用,每个都有一个参数?

2 个答案:

答案 0 :(得分:4)

这是一个带有两个参数的单个方法调用;可能是这样的:

function initWithPressureAndTreadDepth(float pressure, float treadDepth);

答案 1 :(得分:0)

我认为带有命名字段的参数对象是Objective-C概念的良好替代品。

function initWith(arg)
{
    if(arg.pressure < 10.0)
    {
      ...
    }
}
initWith({pressure: pressure, treadDepth: treadDepth});