JSOO(JS面向对象)的一些理解
<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>
作者:ThinkWang
出处:http://www.cnblogs.com/ThinkWang/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

浙公网安备 33010602011771号