就像在C#中的 int sampleMethod(ref object p) { ... }
其中参数p是按引用传递的,这样可以在方法内把p指定为不同于调用前的另外的对象。
在javascript里有没有类似的机制呢?
类似C#中的输出参数呢?(int otherMethod(out object p){...})
其中参数p是按引用传递的,这样可以在方法内把p指定为不同于调用前的另外的对象。
在javascript里有没有类似的机制呢?
类似C#中的输出参数呢?(int otherMethod(out object p){...})
function SomeObj()
{
this.Prop = null;
}function tf(p)
{
p = new SomeObj();
p.Prop = 5;
return 2
}var p = new SomeObj();
p.Prop = 1;
tf(p);
alert(p.Prop);
举个例子:在C#里,
public void SomeMethod(ref int iParam)
{
iParam = iParam + 1;
}调用的代码类似这样:
int i = 1;
SomeMethod(ref i);结果调用完成后,变量i的值为2问题是要完成类似的功能,在javascript中有没有什么办法能够以类似的形式达成这样的效果。如果非得使用一个数组,则只能看作是手动装箱,这种办法有点丑陋。