Blogger Information
Blog 38
fans 0
comment 0
visits 25297
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
第十六课—JavaScript对象 2018年9月11日 20时00分
空白
Original
626 people have browsed it

js创建对象

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js对象</title>
</head>
<body>
<script>
    // 字面量创建对象
    var obg = {
        name : 'ellen',
        age : 20,
        sex : '女'
    }

    console.log(obg.name)
    console.log(obg.age)
    console.log(obg.sex)

    // 使用构造函数创建对象,方法名首字母大写为js构造函数
    function Fun() {}
    Fun.prototype.name = '王炸'
    Fun.prototype.address = '北京'
    Fun.prototype.get=function () {
        console.log(this.name)
    }


    var dj = new Fun();
    dj.get();
    console.log(dj.address)
</script>
</body>
</html>

运行实例 »

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

1.png


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
Author's latest blog post