I'm experimenting with javascript. I'm trying to make a "class" but it is not working like it should. I have problems initiating a new instance of MyClass. See the js fiddle. Is it possible to add a constructor to MyClass just like in php? I'm also not sure that this is the way "classes" are defined in javascript. So any help is more then appreciated.
http://jsfiddle.net/kasperfish/JnvFS/
var MyClass={
test:'hello',
hallo: function(){
alert(this.test);
},
setTest: function(x){
this.test=x;
}
}
MyClass.hallo();
MyClass.setTest('world');
MyClass.hallo();
//not working because MyClass is/does not have a constructor
x= new MyClass;//*
x.hallo();
* firebug: TypeError: MyClass is not a constructor