TomKing9 2022-04-20 14:49 采纳率: 77.8%
浏览 15

class 和 function 的实例化对象的区别

问题遇到的现象和发生背景

为什么class的实例化对象会拷贝类的属性数据,而function的不会。

问题相关代码,请勿粘贴截图
function Person () {
      b = 1
      function fn () {}
    }
    Person.prototype.a = 1
    var persion = new Person()
    console.log(persion);
    console.log('---------')
    class A {
      a = 1
      fn () {
      }
    }
    var a = new A()
    console.log(a)

运行结果及报错内容

img

我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

1条回答 默认 最新

  • 「已注销」 2022-04-20 18:02
    关注

    点开Person的Prototype看看里面是啥~

    评论

报告相同问题?

问题事件

  • 创建了问题 4月20日

悬赏问题

  • ¥15 寻找基于运营商机顶盒的播放器
  • ¥15 fluent二维平板强迫振动
  • ¥15 springboot+Python模型训练 有偿
  • ¥15 关于SQL Server数据库备份还原设置
  • ¥15 the HDL complexity tool使用问题
  • ¥100 用数字代替ip主机号断与旋转链接号段
  • ¥20 学校内手机热点不能使用
  • ¥15 qwen模型微调训练时grad_norm为0.0或为nan
  • ¥15 用vs2022 fortran调试只无法查看数组的值,显示发生未指定的错误
  • ¥15 gge梦幻西游的地图制作