Hi
Sorry I am not sure if this a correctly formulated question, but I wonder if it is possible to put instances of an object (like myFather here) in a separate function. The code I show is not working, it is an example from w3schools, but it demonstrates the best what I would like to achieve:
<script>
function person(firstname,lastname,age,eyecolor)
{
this.firstname=firstname;
this.lastname=lastname;
this.age=age;
this.eyecolor=eyecolor;
}
function(){
myFather2=new person("John","Doe",50,"blue");
document.write(myFather2.firstname + " is " + myFather2.age + " years old.");
}
document.write(myFather.firstname + " is " + myFather.age + " years old.");
</script>
I could take any suggestions regarding if it actually makes sense at all to do that, as obviously I would like properties of myFather (name, age) to be available throughout the code. I am new to js, so please excuse me; I've been trying to find an answer to it over the web, but with no success.