简体   繁体   English

父级继承自子级 - JavaScript

[英]Parent is Inheriting from Child - JavaScript

浏览器控制台截图

Really confused here, checkout the image above.这里真的很困惑,请查看上图。 Why the parent a is inheriting something that i defined for its child?为什么父 a 继承了我为它的孩子定义的东西?

in javascript when you assign an object variable as a variable it is a reference to a single object just like arrays.在javascript中,当您将对象变量分配为变量时,它就像数组一样是对单个对象的引用。 so instead of being a copy of the object it is pointing to the original object in memory.所以它不是对象的副本,而是指向内存中的原始对象。 this means that both a and b are pointing to the same object in memory.这意味着 a 和 b 都指向内存中的同一个对象。 any action taken on one variable will effect the other since they are pointing to the same instance of the object.对一个变量采取的任何操作都会影响另一个变量,因为它们指向对象的同一实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM