0

I was looking at some code on the web and couldn't figure out what the purpose of the relatedObject property of a DOM object was:

this.hotspot = document.createElement('div');
this.hotspot.relatedObject = this;

Anyone have an idea?

Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
LordZardeck
  • 7,953
  • 19
  • 62
  • 119
  • Let me explain the difference between Google and StackOverflow. *"What is X?"* is a question for Google. *"I'm having trouble using X. Can you help?"* is a question for StackOverflow. – Šime Vidas Sep 13 '11 at 13:00
  • and moreover, relatedObject is not a standard DOM property. – Py. Sep 13 '11 at 13:02
  • @Šime Vidas: I didn't find useful results on Google either (especially, since `Related Object` is really a broad term!). I think it's perfectly fine to ask on Stack Overflow, since there seem to be no duplicates... – Lukas Eder Sep 13 '11 at 13:16
  • @Šime Vidas: I think "I'm having trouble understanding this code construct, can you help?" is also an appropriate question for StackOverflow. – Michał Wojciechowski Sep 13 '11 at 13:18
  • @Sime Vidad: I DID google first. Many different pages and many different search terms. But I couldn't find ANYTHING about it. – LordZardeck Sep 13 '11 at 13:48
  • @Michal This is OK: *"I'm having trouble understanding X. I've read article A and article B and I still don't get it."*.However, this is not OK: *"I've seen X in some foreign code. What does it mean?"*. You have to do some elementary research before asking on SO. Googling for "relatedObject" does that. – Šime Vidas Sep 13 '11 at 13:59
  • @Šime Vidas: Agreed. The OP commented that he did google it, so I guess he should have said that in the question in the first place. – Michał Wojciechowski Sep 13 '11 at 14:02
  • @Lukas Well, the term "related object" indeed doesn't give you useful results. However, property names and method names luckily use one-word camel-case notation, so you search for "relatedObject" which gives you useful results. – Šime Vidas Sep 13 '11 at 14:02
  • @Sime Vidas: would you mind sharing even ONE of those useful results, cause I couldn't find even ONE. – LordZardeck Sep 13 '11 at 15:30
  • @Lord There aren't any. My mistake. – Šime Vidas Sep 13 '11 at 16:25

2 Answers2

3

This isn't a standard property. It's probably just a method of binding a JS object to a particular HTML element, for example to be able to retrieve the object easily in an event handler later on.

  • So whoever wrote the code just added the property? I guess I didn't think you could do that to elements. So the nest step is to search ALL the code and try and find where it's being used...:P. Thanks for the help. – LordZardeck Sep 13 '11 at 13:50
  • @LordZardeck: That's right. If you'd like to know more, here's an interesting discussion about custom attributes: http://stackoverflow.com/questions/992115/custom-attributes-yay-or-nay – Michał Wojciechowski Sep 13 '11 at 13:59
  • Ok, i finally found out where it was used after digging through thousands of lines of code. :p You were right. It seems to just be added there to give access to that object in another class. – LordZardeck Sep 13 '11 at 22:20
0

I do not believe this is a standard property, but rather a property that is being created by virtue of assigning it to hotspot, probably to track the reference of the object that created it.

Ryan Wright
  • 3,333
  • 2
  • 16
  • 9