继承的另一种写法

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>继承的另一种写法</title>
<script>
var Animal = function () {};

Animal.prototype.breath = function () {
    console.log('breath');
};

var Dog = function () {};

// Dog 继承了 Animal
Dog.prototype = new Animal;

Dog.prototype.wag = function () {
    console.log('wag tail');
};

var dog = new Dog;
dog.wag();
dog.breath();  // 继承的属性
</script>
</head>

<body>
</body>
</html>
posted @ 2013-03-15 16:16  baiezone  阅读(184)  评论(0编辑  收藏  举报