Javascript Object Question

I am a beginner w / Javascript. I am looking at the following code someone else wrote:

function MeetingPage()
{
   MeetingPage.colors = new Object();
}

...

var meeting = new MeetingPage();

From what I saw, I believe that the MeetingPage function creates an object that someone later holds in the meeting. What is MeetingPage.colors? Is MeetingPage prefix kind of global? Is this a "this" pointer?

Any suggestions would be appreciated.

+3
source share
3 answers

This is actually just bad code. MeetingPage.colors = new Object();sets a property colorsin a functionMeetingPage , i.e.

function MeetingPage(){ }
MeetingPage.colors = {};

This is perfectly true since all functions in JavaScript are objects. The problem is that if you have multiple instances of the meeting page:

var meeting1 = new MeetingPage();
var meeting2 = new MeetingPage();

reset colors. this.colors = {}, , .

+8

This is the JavaScript syntax for creating class properties. Note that this class property is not an instance property , which means it is common to all instances of the class. (If you know C ++, it looks like a static class). However, I did not think it would be fair to put a class property inside the constructor itself. I would think that every time a new MeetingPage is created, the property of the color class will be destroyed.

0
source

All Articles