Hello,
How do I create a method in an object,
Thanks
Pierre
example:
// code
function house(type, location) // constructor “house”
{
this.type = type;
this.location = location;
}
house1 = new house(villa, hawai); //creating an instance
// end code
For retrieving e.g. the variables type and location, how do I create the methods getType and getLocation.
I expected the following would work but it does not:
//code
function house(type, location) //constructor
{
this.type = type;
this.location = location;
function getType() // create method getType
{ return type; }
function getLocation() // create method getLocation
{ return location; }
}
house1 = new house(villa, hawai); //create an instance
houseType1 = house1.getType(); // retrieve variables
houseLocation1 = house1.getLocation();
trace( houseType+" "+houseLocation1); // print variables
// end code