JavaScript

//There are no Classes in Javascript!//This is a Workaround, simulating something similar,//so one is able to encapsulate his code like he's used to in *better* languagesfunctionMyClass(val){//Konstruktor//necessary to be able to acces this from everywhere in the "class"(methods)varthat=this;//private attributevarx=val;//public attributethat.y=0;//public method that.publicMethod=function(){privateMethod();}//private methodfunctionprivateMethod(){alert(that.x);}//"global" methodglobalMethod=function(){alert(that.x)}}varobject=newMyClass(10);object.publicMethod();globalMethod();