首页 > 其他 > 详细

3.2 JacaScript面向对象

时间:2015-02-13 13:10:31      阅读:251      评论:0      收藏:0      [点我收藏+]

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. 面向对象例子

 

3.2 JacaScript面向对象

原文:http://www.cnblogs.com/iMirror/p/4289949.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!