日期:2014-05-18 浏览次数:20879 次
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>试试</title>
</head>
<script type="text/javascript">
var Test = function(p1, p2, p3) {
this.p1 = p1 || 'p1',
this.p2 = p2 || 'p2',
this.p3 = p3 || 'p3'
}
Test.prototype = {
getP1 : function() {
return this.p1;
},
getP2 : function() {
return this.p2;
},
getP3 : function() {
return this.p3;
}
}
window.onload = function() {
var t0 = new Test();
alert('p1=' + t0.getP1() + ', p2=' + t0.getP2() + ', p3=' + t0.getP3());
var t1 = new Test('1');
alert('p1=' + t1.getP1() + ', p2=' + t1.getP2() + ', p3=' + t1.getP3());
var t2 = new Test('1', '2');
alert('p1=' + t2.getP1() + ', p2=' + t2.getP2() + ', p3=' + t2.getP3());
var t3 = new Test('1', '2', '3');
alert('p1=' + t3.getP1() + ', p2=' + t3.getP2() + ', p3=' + t3.getP3());
}
</script>
<body>
</body>
</html>