这种写在function里的function相当于Class里的private定义的方法,在类外是访问不到,只能是类内的函数方法能调用到。所以你得在这个名称空间里加入类似于 public 的定义:
function MyNamespace()
{
function A()
{
return B()*10;
};
function B()
{
return 100;
}
function MM(name)
{
alert("MM function is runing! "+ A());
this.name = name;
}
MM.prototype.getValue = function()
{
return "name = "+ this.name +"\nvalue = "+ A();
}
return MM; //这就是访问到类内函数的入口。
}
var e = new (MyNamespace())("meizz");
alert(e.getValue());
function MyNamespace()
{
function A()
{
return B()*10;
};
function B()
{
return 100;
}
function MM(name)
{
alert("MM function is runing! "+ A());
this.name = name;
}
MM.prototype.getValue = function()
{
return "name = "+ this.name +"\nvalue = "+ A();
}
return MM; //这就是访问到类内函数的入口。
}
var e = new (MyNamespace())("meizz");
alert(e.getValue());
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货