I am trying to use something similar to Objects/Classes in JavaScript. I found out that this can be done via a function. So my class code is like this: (using jQuery)
function InfoBox(Box) { // My class
this.Box = Box; // html element
this.Text = 'Information here';
this.Image = 'foo.png';
setText = function () {
this.Box.children('.Text').html(this.Text);
}
}
The variables in the function work fine but whenever I call the method/function "setText" via
var iBoxUser = new InfoBox($('.iBoxUser'));
iBoxUser.Text = 'Welcome';
iBoxUser.setText(); // Error occurs here
I get the error: "Uncaught TypeError: undefined is not a function"
It seems that I'm somehow doing the function thing wrong. Or can functions even contain other functions?