js中对象创建方式及其优势和不足1

来源:互联网 发布:下载机械制图软件 编辑:程序博客网 时间:2024/05/19 00:07
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>js对象的创建1</title>
    <meta name="author" content="ASUS" />
    <!-- Date: 2014-11-13 -->
    <script type="text/javascript">
        //外部属性定义方式
        //在js中不存在类  所以可以直接通过Object来创建对象
        //但是使用如下的方式创建对象,存在很大的不足,由于没有类的约束  无法实现对象的重复利用
        //并且没有一种约定 ,在操作时候会带来问题

        var person = new Object();
         person.name="张三";
         person.age=20;
         person.sayHello = function(){
             alert(person.name+","+person.age);
         }
         person.sayHello();
    </script>
</head>
<body>

</body>
</html>
0 0