Object Oriented JavaScript for .Net Developers

JavaScript could feel like a ‘pain’ to deal with at first if you are coming from more ‘traditional’ object oriented languages like C#. However, it’s no longer possible to ignore JavaScript as a glue or toy language. Microsoft is adopting it as a first class language with JavaScript and HTML5 as the primary application development tools for Windows 8. Microsoft is even supporting the Nodejs development efforts, which is a platform built on Google’s V8 JavaScript engine. Even with its design flaws, JavaScript is becoming the universal language with an ability to run on the client, server and mobile devices. HTML5 and JavaScript are becoming a driving force of the web and it’s changing the way you develop web applications. So love it or hate it, you can’t avoid JavaScript if you are creating for the web.

Following are few reasons why developers coming with standard Object Oriented background dislike JavaScript

  • It seems to violate many traditional programming principles
  • Inconsistent rules - what works in one context doesn’t seem to work in other
  • Difficult to follow code - it doesn’t appear to have any consistent structure
  • Doesn’t work consistently across different browsers

JavaScript has matured a lot in last few years. You could write your client side code with as much confidence as the server side code. You could apply your knowledge of design patterns to the client side code as well.

JavaScript does support object orientation. However, it doesn’t force you to write object-oriented code by default like C#. Possibly, the majority of the JavaScript code you have come across might not have been written in object oriented fashion. In fact, you don’t have to write your JavaScript code in object-oriented fashion; however it makes lots of sense to do so when you are writing your server side code in familiar OO style. Increasing scope and complexity of client-side code requires robust structure and organization.

I am writing series of articles addressing various aspects of object-oriented programming in JavaScript from .Net/C# developer’s viewpoint. Following are the topics covered in this series

  1. Defining Classes
  2. Inheritance
  3. Namespaces
  4. Modules