Blogger Information
Blog 32
fans 0
comment 0
visits 22561
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
0710. 写一个构造函数来创建对象,向构造函数的prototype中添加成员,实现数据在实例间共享
Yx的博客
Original
470 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>0710作业</title>
</head>
<body>
<script>
    var createobj =function () {

        this.domin = "baidu.com";
        this.get = function (value) {
            var site = '百度搜索引擎';
            return site + value;
        };


    };

        var obj1 = new createobj();

    console.log(obj1.get(obj1.domin));
//访问内部成员
    var obj2 = new createobj();

    console.log(obj1.get(obj2.domin));
    
    Createobj.prototype.email ='www.baidu.com';
    Createobj.prototypi.hello = function() {
        return'hello baidu';
    }
    
</script>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

Correction status:qualified

Teacher's comments:这些都是最基本的知识点, 想深入学习可以参考: MDN
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
Author's latest blog post