new 决定 prototype 是对象还是方法

作者:vkvi 来源:ITPOW(原创) 日期:2008-6-23
<script type="text/javascript">
<!--
function Cftea()
{
}
 
function F1(i)
{
    this.i = i;
}
 
function F2(j)
{
    this.j = j;
}
 
Cftea.prototype.F1 = new F1(1);
Cftea.prototype.F2 = F2;
 
var cftea = new Cftea();
//cftea.F1(11); //错误,F1 是个对象,而不是方法
alert(cftea.F1.i); //正确,访问 F1 对象中的成员
cftea.F2(22); //正确,F2 是 cftea 的一个方法
//alert(cftea.F2.j); //错误,F2 不是 cftea 的一个对象
-->
</script>

相关阅读

相关文章