javascript的this与prototype的区别

<!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>
原文地址:https://www.cnblogs.com/buexplain/p/4422357.html