zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    oracle一次插入多条数据
    SQL在in中传入参数类型问题
    斗鱼刷弹幕定时
    在setTimeout 200ms后执行函数发生错误
    Java去除字符串中的空格
    同步与异步
    HTTP请求中GET和POST的区别
    SQL优化
    什么是死锁以及避免死锁
    常用快捷键
  • 原文地址:https://www.cnblogs.com/buexplain/p/4422357.html
Copyright © 2011-2022 走看看