Blogger Information
Blog 11
fans 2
comment 0
visits 8250
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
对象的基础、构造函数与原型对象--2019-07-10 22:22
烦帅不防晒
Original
577 people have browsed it

一、对象的基础 :创建对象:全局成员

                        对象成员: 包括对象中的变量和函数

                        对象变量: 属性(property)

                      对象函数: 方法(method)

 二、对象的复制:一处创建,多处调用

三、构造函数:创建彼此关联的对象

四、静态成员:直接将属性与方法添加到构造函数上

五、原型成员:添加到构造函数原型对象上的成员,将被所有实例共享

1)XX$[RRZ7(JET[HM}~Y2LK.png

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>对象的作用</title>
</head>
<body>
<script>

    var domain ="baidu.com";
    var get =function (value) {
        var site ="百度一下:" ;
        return site +value;
    };
    console.log(get(domain));


    // 创建对象
    var obj1 ={};
    obj1.domain="baidu.com";
    obj1.get= function (value) {
        var site ="百度一下  你就知道:";
        return site + value
    };
        console.log(obj1.get(obj1.domain));


 // 对象复制
    var createobj =function () {
        return {
            domain: 'php.cn',
            get: function (value) {
                var site = "php中文网";
                return site + value;
            }
        };
    };
    var obj2=createobj();
    console.log(obj2.get(obj2.domain));

    var obj3=createobj();
    console.log(obj3.get(123));

    // 构造函数  创建彼此关联的对象
    var Createobj =function () {
        this.domain = "baidu.com";
        this.get= function (value) {
            var  site ="百度一下";
            return site + value
        }
    };
    var obj2 = new Createobj();
    console.log(obj2.domain);
    console.log(obj2.get(321));


    // 静态成员
    Createobj.mail='321@qq.com';
    console.log(Createobj.mail);

   // 原型成员
    Createobj.prototype.mail='123@qq.com';
    console.log(obj2.mail);










</script>

</body>
</html>






Correction status:qualified

Teacher's comments:赶紧跟上学习的进度
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments