Select to view content in your preferred language

Tips for cleaner javascript code?

799
2
04-04-2014 11:42 AM
MarioFlores
New Contributor
I'm currently developing an application in JavaScript which is coming along really nice. However the code is a giant mess; I cannot find problems easily or even know where to add new features sometimes. I'm a fan of OOP design and my stronghold is mainly Java, but when I try to implement the same ideas in JavaScript it doesn't work out as well as it should.

I'm not entirely sure if this is because I lack knowledge on JavaScript, or it just cannot be done after initiating a map method and using dojo.connect().

Anyways, my question is: Is there any tips or main pitfalls when trying to create an object oriented JavaScript code with the ArcGIS API? I mainly want this to split features in different .js files. Right now it's literally just a massive .js file with all my code.
0 Kudos
2 Replies
RobertoPepato
Deactivated User
I'm currently developing an application in JavaScript which is coming along really nice. However the code is a giant mess; I cannot find problems easily or even know where to add new features sometimes. I'm a fan of OOP design and my stronghold is mainly Java, but when I try to implement the same ideas in JavaScript it doesn't work out as well as it should.

I'm not entirely sure if this is because I lack knowledge on JavaScript, or it just cannot be done after initiating a map method and using dojo.connect().

Anyways, my question is: Is there any tips or main pitfalls when trying to create an object oriented JavaScript code with the ArcGIS API? I mainly want this to split features in different .js files. Right now it's literally just a massive .js file with all my code.


This is a very common situation. I believe that this happens because Javascript is probably the world's most misunderstood  programming language. First of it all, it has "Java" on its name but the ideas and philosophy of the language has little or nothing to do with Java. Its much more like LISP in C clothes. I recommend you to read the amazing Crockfords' Book - Javascript: The Good Parts. After that, take a look at AMD and modularization of javascript code.

If you are looking for a framework that provides you ways of organizing your code (much like the mvc pattern), you may wan't to take a look at this link.

Regards,

Roberto Pepato
0 Kudos
PatrickWild3
Regular Contributor

Hi Roberto,

Can you repost the link?

Thanks,

PW

0 Kudos