JS基础学习1——什么是基础js类和原型?

<!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>
原文地址:https://www.cnblogs.com/91allan/p/5412597.html