I want to create a simple object and then use a constructor to fill that object just like you can in an OOP language. Why is Javascript not letting me create a basic object
person = new Object();
Question: What would be the best way to declare an object in Javascript so that it basically follows that same convesion as Java and C++?
I would like to be able to add in the object properties before I use them in the code.
Code:
<!DOCTYPE html>
<html>
<body>
<script>
person=new Object(); <-- will work with out this code
function person(firstname,lastname,age,eyecolor)
{
this.firstname=firstname;
this.lastname=lastname;
this.age=age;
this.eyecolor=eyecolor;
}
myFather=new person("John","Doe",50,"blue");
document.write(myFather.firstname + " -- " + myFather.age);
</script>
</body>
</html>