Programming large scripts in javascript using object orientated style coding

November 12, 2010

This week whilst coding a large javascript / jQuery script for one of our online games which started to grow to an unmanageable size and needed to be compartmentalized I decided to review my techniques.

Previously for scripts which were quite large I would create an object which contained lots of different methods like so. As you should already know in js its all about scope.

So here's what I used to do:

function page(){
this.funcName = function(param){
alert("hey man this is a cool little function);

I'd then go and call this function into the page like so.

var mypage = null;
function init(){
mypage = new page();


About me

Hello! I'm David Heward, how are you going? I'm a Senior Devops/Build Engineer, specialising in AWS & Cloud Automation. Based in London. Strong 10+ year background in Software development. Have a read of my blog. Have a look at some of my working projects. Contact me at @davehewy or on Linkedin.