3 Replies - 310 Views - Last Post: 11 November 2019 - 01:44 AM

#1 Druzel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-November 19

Sharing a data object between 2 objects.

Posted 06 November 2019 - 08:21 AM

Hello Guys

I have created 3 objects in separate files in Javascript. One object reads data and performs actions. One Object sets data and reports on actions taken. One object holds the data to be read and set. I can get the objects to read the data so long as I import the data into each object. However in doing this any changes to the data are lost on import. I need to import the data onto one object and have a reference to the data in the second object but have no clue how this works.

So in essence I need a shared data object that can be used by two other objects. When one object updates that object the other can read it. Any ideas on how this can be achieved.

Many thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Sharing a data object between 2 objects.

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4245
  • View blog
  • Posts: 13,452
  • Joined: 08-June 10

Re: Sharing a data object between 2 objects.

Posted 06 November 2019 - 08:42 AM

Since you didn't provide any hints on what you actually do, I can only point you to the Observer Pattern.
Was This Post Helpful? 0
  • +
  • -

#3 Druzel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-November 19

Re: Sharing a data object between 2 objects.

Posted 08 November 2019 - 10:32 AM

Thanks for the feedback.

I have now resolved this by passing the data object by reference.
Many thanks for the feedback.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4245
  • View blog
  • Posts: 13,452
  • Joined: 08-June 10

Re: Sharing a data object between 2 objects.

Posted 11 November 2019 - 01:44 AM

View PostDruzel, on 08 November 2019 - 07:32 PM, said:

I have now resolved this by passing the data object by reference.


Erm, objects are always passed by reference...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1