I'm totally new to Javascript and this seems like something that should be very simple, but I can't see why my code isn't working. Here's an example of the problem I'm having:
//Thing constructor
function Thing() {
function thingAlert() {
alert("THING ALERT!");
}
}
//Make a Thing
var myThing = new Thing();
//Call thingAlert method
myThing.thingAlert();
An object is created, but I can't call any of its methods. Why, in this example, is thingAlert() not being called?
Thingdoes not have any methods. All you do inside the constructor function is creating a local function. That function is garbage-collected afterThingsterminates. It works the same way like with any other function.