Difference between reference and instance in javascript

后端 未结 8 2074
长情又很酷
长情又很酷 2020-12-23 23:10

Sometimes I hear people say \"a reference to a object\" and some say \"a instance of a object\" What is the difference?

相关标签:
8条回答
  • 2020-12-23 23:37

    We always use a reference to an object and cannot use the object directly, we can only use the reference. Object instance itself is in memory.

    When we create an object, we get a reference. We can create more references:

    var obj = {}; // a reference to a new object
    var a = obj; // another reference to the object
    
    0 讨论(0)
  • 2020-12-23 23:38

    A variable will hold a reference to an instance of an object.

    The actual object is an instance.

    The variable/variables used to access the object hold the references to it.

    0 讨论(0)
提交回复
热议问题