欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

對(duì)象創(chuàng)建的幾種方式

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <script type="text/javascript">
            // 1    {}
            var a = {};
            a.name = "john";
            a.age = 22;
            a.sayHello = function(){
                console.log(this.name);
            }
            a.sayHello();
            console.log(a.name + "," + a.age);

            // 2    new Object()
            var b = new Object();
            b.name = "jx";
            b.age = 21;
            b.sayHello = function(){
                console.log(this.name + "," + this.age);
            }
            b.sayHello();
            console.log(typeof b)
            console.log(b instanceof Object)

            // 3    字面量
            var person = {
                name:"pd",
                age:20,
                sayHello:function(){
                    console.log(this.name + "," + this.age);
                }
            }
            person.sayHello();
            console.log(typeof person);

            // 4    工廠模式
            function obj(name,age){
                var a = new Object;
                a.name = name;
                a.age = age;
                a.sayHello = function(){
                    console.log(this.name + "," + this.age)
                }
                return a
            }

            var a1 = obj("nv",25);
            var a2 = obj("sd",28);
            a1.sayHello();
            a2.sayHello();

            //  5   構(gòu)造函數(shù)創(chuàng)建
            function Person(name,age){
                this.name = name;
                this.age = age;
                this.sayHello = function(){
                    console.log(this.name + "," + this.age);
                }
            }
            var person2 = new Person("mv",29);
            var person3 = new Person("be",30);

            person2.sayHello();
            person3.sayHello();
            console.log(typeof person2,typeof person3);
            console.log(person2.sayHello === person3.sayHello)
            // 沒解決方法共享問題

            //  6   原型模式創(chuàng)建
            function Animal(){};
            Animal.prototype.name = "sdf";
            Animal.prototype.age = 23;
            Animal.prototype.sayHello = function(){
                console.log(this.name + "," + this.age);
            }
            var animal1 = new Animal();
            var animal2 = new Animal();

            animal2.name = "bsdb"

            animal1.sayHello();
            animal2.sayHello();

            console.log(typeof animal1,typeof animal2);
            console.log(animal1.sayHello === animal2.sayHello);

            //  6-1     原型模式2
            function Animal1(){};
            Animal1.prototype = {
                name:"sadf",
                friends:['car','dog'],
                age:56,
                sayHello:function(){
                    console.log(this.name + ',' + this.age + ',' + this.friends);
                }
            }
            var animal3 = new Animal1();
            var animal4 = new Animal1();
            animal3.friends.push('snake');
            animal4.friends.push('sheep');
            animal4.name = "xcv";
            animal3.name = "bnf";
            console.log(animal3.friends)
            console.log(animal4.friends)
            animal3.sayHello();
            animal4.sayHello();
            //如果里面有引用類型friend  則改一個(gè)全改

            //  原型+構(gòu)造函數(shù)
            function Power(name,age){
                this.name = name;
                this.age = age;
                this.friends = ['car','bus'];
            }
            Power.prototype.sayHello = function(){
                console.log(this.name + ',' + this.age + ',' + this.friends)
            }
            var power = new Power('bcb',56);
            var power1 = new Power('nbgh',89);

            power.friends.push('caps');
            power1.friends.push('faker')

            power.sayHello();
            power1.sayHello();

            console.log(power.friends)
            console.log(power1.friends)
        </script>
    </body>
</html>

當(dāng)前標(biāo)題:對(duì)象創(chuàng)建的幾種方式
網(wǎng)頁網(wǎng)址:http://www.aaarwkj.com/article46/peiohg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作域名注冊(cè)、營銷型網(wǎng)站建設(shè)、網(wǎng)站收錄、網(wǎng)站策劃、網(wǎng)站排名

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站
免费人成黄页网站在线播放国产 | 欧洲精品久久久久久| 五月婷婷丁香综合中文字幕| 午夜性色福利在线播放 | 人成午夜视频在线播放| 日韩精品人妻一区二区免| 天天干天天干夜夜操| 日本一区二区三区免费不卡视频| 国产日韩欧在线视频| 91中文字幕国产日韩| av天堂资源在线播放| 亚洲免费麻豆一区二区三区| 国产美女极度色诱视频| 亚洲一区二区三区伊人| 在线午夜免费视频观看| 精品毛片在线播放网站不卡| 精品日韩av高清一区二区三区| 国产熟女高潮一区二区| 欧美日韩黄色人人小视频| 日韩中字伦理熟妇人妻| 秋霞三级在线免费观看| 真实国产熟女一区二区三区| 蜜桃视频在线观看视频免费| 91成人伦理在线观看| 免费亚洲一区二区三区| 亚洲蜜桃精品一区二区三区| 日本岛国免费一区二区| 欧美精品国产精品久久| 黑丝美女大战白丝美女| 精品一二三四五区亚洲乱码| 亚洲一级特黄大片在线观看| 白白色成人在线免费视频| 成人嚼牙特别黑黄怎么办| 亚洲三级伦理在线视频| 国产一区二区主播不卡| 国产午夜福利不卡在线观看| 少妇一区二区三区免费| 国产精品国产三级农村av| 国产欧美日本一区二区| 一区二区三区在线观看淫| 日韩伦理高清在线观看|