function test_opp(name,age){
this.name=name;
this.age=age;
this.ha=1;
var tp=412;//私有变量 function test_priviate(){//私有方法 alert("it is a private"); } test_priviate(); this.gettp=function(){//通过这个访问私有变量 return tp; }
}
test_opp.prototype.huha = function(ele){
alert(ele);
}
test_opp.prototype.ha=2;
var opp = new test_opp("sunhongwei","25");//function test_opp()是构造函数
opp.huha("good");
alert(test_opp.ha);//弹出的是undifine 不能用原型拿prototype
alert(opp.ha);//弹出1
alert(opp.gettp());//弹出412
function test_opp2(){
this.name="test";
}
test_opp2.prototype = new test_opp("hei","24");
test_opp2.clone=function(){//静态方法
alert(778);
};
var opp2= new test_opp2();
test_opp2.clone();//弹出778
opp2.clone();//报错
alert(opp2.name);//弹出test
alert(opp2.age);//弹出24
327

被折叠的 条评论
为什么被折叠?



