Blogger Information
Blog 27
fans 0
comment 0
visits 17919
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
创建对象的方式(字面量或构造函数-9.11
Yyk.的博客
Original
657 people have browsed it

创建对象的方式

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>基本语法</title>
    <script type="text/javascript">
        //创建对象方式:
        //字面量
        var obj1= {name:'YHF',age:20,salary:5000}
        //构造函数
        var obj2=new Object()
        obj2.name='YHF'
        obj2.age=20
        obj2['salary']=6000
        console.log(obj2)
        console.log(obj1)
        //new 函数名()也是可以创建的
    </script>
</head>
<body>

</body>
</html>

运行实例 »

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

字面量

var obj = {

    name = 'Y',

     age:19

}


构造函数

$obj = new object();

obj.name = 'Y';

obj.age = 19


个人总结:

JS真的是一门神奇的语言,它能做出的效果也是千奇百怪,很值得去深入学习啊。

Correction status:unqualified

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