JS中属性注意点

51 阅读1分钟
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <script>
        function Person(myName, myAge)
        {
            this.name=myName;
            this.age=myAge;
        }
        Person.prototype={
            constructor:Person,
            currentType:"ren",
            say:function()
            {
                console.log("666");
            }
        };
          let obj = new Person("lnj", 34);
          console.log(obj.currentType);
          console.log(obj.__proto__.currentType);
          obj.currentType="新设置的值";
          console.log(obj.currentType);
          console.log(obj.__proto__.currentType);
    </script>
</body>
</html>