Simple getter and OO in Javascript

Had a little drawback developing dia2statemachine because JS weird way of being poo Object Oriented.

Just so people know, there are setters and getters in DECENT BROWSERS , but of course IE doesn´t use them! They can significantly simplify the code, but what the helll, let´s keep it compatible at this time…

I was having lot´s of trouble to get a value out of a class in JS, turn´s out that, if there is a var a = true; inside a class I don´t have access to it from outside from calling, object.a -> (undefined), in the other hand, if it is declared inside the class as this.a = true , then I have access outside (set and get) but that is not O.O.

So a very simple way to make getters is>

snipp d2s

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s