javascript自定义对象的三种方式

//

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
    people = new Object();
    people.name = "aaronswartz";
    people.age = 26;
    people.sex = "male";
    document.write("name:"+people.name+"<br/>");
    document.write("age:"+people.age+"<br/>");
    document.write("sex:"+people.sex+"<br/>");
</script>
<hr/>
<script type="text/javascript">
lang={name:"javascript",
          age:23
          }
    document.write("name:"+lang.name+"<br/>");
    document.write("age:"+lang.age+"<br/>");
</script>
<hr/>
<script type="text/javascript">
function person(name,height,weigh){
        this._name=name;
        this._height=height;
        this._weigh=weigh;
    }
rose = new person("DerrickRose","4800px","90kg");
            document.write("name:"+rose._name+"<br/>");
            document.write("height:"+rose._height+"<br/>");
            document.write("weigh:"+rose._weigh+"<br/>");
</script>
</body>
</html>


你可能感兴趣的:(javascript自定义对象的三种方式)