码迷,mamicode.com
首页 > 其他好文 > 详细

3.2 JacaScript面向对象

时间:2015-02-13 13:12:22      阅读:207      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!