码迷,mamicode.com
首页 > 编程语言 > 详细

javascript的this与prototype的区别

时间:2015-04-13 16:13:29      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>Document</title>
</head>
<body>
    <script type="text/javascript">
        function C__construct() {
            this.name = 张三;
        }
        C__construct.prototype.age = 25岁;

        var C1 = new C__construct();
        var C2 = new C__construct();

        document.write(C1.name +C1.name+<br/>);
        document.write(C2.name +C2.name+<br/>);
        C1.name = 李四;
        document.write(改变C1.name的值后再次输出C1.name与C2.name<br/>);
        document.write(C1.name +C1.name+<br/>);
        document.write(C2.name +C2.name+<br/>);
        document.write(----------------------------------------分割线----------------------------------------<br/>);
        document.write(C1.age +C1.age+<br/>);
        document.write(C2.age +C2.age+<br/>);
        C__construct.prototype.age = 26岁;
        document.write(改变C__construct.prototype.age的值后再次输出C1.age与C2.age 继承的意义就在于此处<br/>);
        document.write(C1.age +C1.age+<br/>);
        document.write(C2.age +C2.age+<br/>);
        document.write(改变C1.age的值后再次输出C1.age与C2.age<br/>);
        C1.age = 27岁;
        document.write(C1.age +C1.age+<br/>);
        document.write(C2.age +C2.age+<br/>);
    </script>
</body>
</html>

 

javascript的this与prototype的区别

标签:

原文地址:http://www.cnblogs.com/buexplain/p/4422357.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!