I'm a beginner w/ Javascript. I'm looking at the following code that someone else wrote:
function MeetingPage()
{
MeetingPage.colors = new Object();
}
...
var meeting = new MeetingPage();
From what I've seen, I believe that the MeetingPage function creates an object that later someone holds onto in meeting. What is the MeetingPage.colors? Is the MeetingPage prefix some kind of global? Is it a "this" pointer of some kind?
Any suggestions would be appreciated.
It's actually just bad code. MeetingPage.colors = new Object(); is setting a property called colors on the MeetingPage function, i.e:
function MeetingPage(){ }
MeetingPage.colors = {};
Which is perfectly valid since all functions in JavaScript are objects. The problem is that if you have multiple instances of meeting page:
var meeting1 = new MeetingPage();
var meeting2 = new MeetingPage();
The code you posted will reset colors. It should either should be written as this.colors = {}, or it should be set outside of the function as in my first snippet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With