<script type="text/javascript">
///<summary>
/// Animal类
///</summary>
function Animal(name) {
//属性
this.Name = name;
//public 方法
this.Shout = function () {
alert("我是一只Animal,我的名字叫 " + this.Name);
};
//private 方法
var _Shout = function () {
alert("private _Shout");
};
};
///<summary>
/// Cat类
///</summary>
function Cat() {
this.Catch = function () {
alert("我是一只Cat,我在捉老鼠");
};
//Cat类自己Shout
//this.Shout = function () {
// alert("我是一只Cat,喵喵~");
//};
};
Cat.prototype = new Animal(); //Cat继承自 Animal
//测试
window.onload = function () {
var a1 = new Animal();
a1.Name = "咪咪a1";
a1.Shout();
//构造方法
var a2 = new Animal("旺旺a2");
a2.Shout();
var c1 = new Cat();
c1.Name = "拉拉c1";
c1.Catch();
c1.Shout();
};
</script>
相关文章: