不知道你要实现什么?看看下面的程序也许有帮助 <script language=javascript> function a() { this.b(); } a.prototype.b=function() { alert("haha2") } var c=new a(); </script>
In netscape or mozilla browser, you can use a.b() to call the inner function.
function 里套用 function 类似于类里的 private 方法,在外面是没有办法调用到的,只能是做一个入口。<SCRIPT LANGUAGE="JavaScript"> <!-- function a() { function b() { alert("function b is runing!"); } function Mzclass() { this.name = "Meizz"; } Mzclass.prototype.b = function() { b(); return this.name; } return Mzclass; } var c = new (a())(); alert(c.b()); //--> </SCRIPT>
<script language=javascript>
function a()
{
this.b();
}
a.prototype.b=function()
{
alert("haha2")
}
var c=new a();
</script>
<!--
function a()
{
function b()
{
alert("function b is runing!");
}
function Mzclass()
{
this.name = "Meizz";
}
Mzclass.prototype.b = function()
{
b();
return this.name;
}
return Mzclass;
}
var c = new (a())();
alert(c.b());
//-->
</SCRIPT>