首页 > 编程语言 > 详细

javascript的this与prototype的区别

时间:2015-04-13 16:10:59      阅读:175      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!