有人可以在下面提示我嗎? -使用Javascript中的別名命名空間
1)如何使用「Base」變量?
2)在callShowMsg函數中,局部變量「ns」用於別名命名空間。
是否可以使用全局變量來別名命名空間?它將避免需要在每個函數中聲明局部變量。
在此先感謝。
我的代碼,
var Base = namespace("MyCo.MyApp.Myprogram");
MyCo.MyApp.Myprogram =
{
showMsg: function (pMsg)
{
alert(pMsg);
},
callShowMsg: function (pMsg)
{
var ns = MyCo.MyApp.Myprogram;
ns.showMsg('Hello');
}
}
這看起來不像是一個有效的JavaScript給我。 – thefourtheye
@thefourtheye看起來完全對我有效。 'namespace'大概只是定義一個嵌套對象的函數。 – meagar
@meagar謝謝澄清。 :) – thefourtheye