index

Javascript object oriented programming

This implementation shows you how to code javascript in a object oriented manner (java, c# etc). Download all the html page and files in order to see that the class 'Class1' is, in fact, in a directory named packageName, and the file is Class1.js

//namespace-package
var packageName={};

//Class definition
packageName.Class1=function(name){
this.name=name;
}
packageName.Class1.prototype.instanceMethod=function(){alert ("Hello instance "+this.name);};
packageName.Class1.staticMethod=function() {alert ("Hello static");}

//hint, if you don't want to drag the packages when typing you can declare a new variable
var Class1=packageName.Class1;

//create an instance of Class1 var class1=new packageName.Class1("Raiko"); is also valid, but longer!!!
var class1=new Class1("Raiko");
//Execute instance method
class1.instanceMethod();
//Execute static method
Class1.staticMethod();