发哥要做活神仙

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <script>
    //声明一个类
    function Person(name,age)
    {
        this.name=name;
        this.age=age;
    }
    //使用原型给类添加方法
    Person.prototype.show=function()
    {
        alert("我叫"+this.name+",今年"+this.age);
    }
    //创建两个对象
    var person1 =new Person('张三',20);
    var person2 =new Person('李四',23);
    //调用原型里面的方法
    person1.show();
    person2.show();
    </script>
</head>
<body>
     
</body>
</html>

 

posted on 2016-04-20 14:35  发哥要做活神仙(笔记)  阅读(164)  评论(0编辑  收藏  举报