3.2 JacaScript面向对象

1. 面向对象

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <p id="pTime"></p>
    <script src="myjavascript.js">
    </script>
</body>
</html>
/**
 * Created by Administrator on 2015/2/13.
 */
var person = {
    name:"mirror",
    age:30,
    eat:function(){
        alert("吃货")
    }
}
alert(person.name);

 

2. 继承

/**
 * Created by Administrator on 2015/2/13.
 */
function Person(){}
function Student(){}

Person.prototype.say = function () {
    alert("hello");
}

Student.prototype = new Person();

var s = new Student();

s.say();

 

3. 复写

/**
 * Created by Administrator on 2015/2/13.
 */
function Person(){}
function Student(){}

Person.prototype.say = function () {
    alert("hello");
}

Student.prototype = new Person();
Student.prototype.say() = function() {
    alert("stu-hello");
}

var s = new Student();
s.say();

 

 

3. 面向对象例子

 

posted @ 2015-02-13 11:16  Mirrorhanman  阅读(104)  评论(0编辑  收藏  举报