jecommera
asked on
please see what is wrong with my object literal
I get an "Car.display is not a function Car.display();" error.
Not sure why this is happening as I have included the method in the object.
Can someone please take a look?
thanks...
<html>
<head><title>Object object</title>
<script type="text/javascript">
var Car = {
make:undefined,
year:2006,
price:undefined,
owner : {
name:"Henry Lee",
cell_phone:"222-222-2222",
address: {street:"10 Main",
city:"SF",
state:"CA"
},
dealer:"SF Honda",
display: function() {details="Make: "+Car.make+"\n";
details += "Year:"+Car.year+"\n";
alert(details);
}
}
};
</script>
</head>
<body bgColor="#EOFFFF">
<script type="text/javascript">
Car.make="Honda Civic";
Car.year=2009;
Car.display();
</script>
</body>
</html>
Not sure why this is happening as I have included the method in the object.
Can someone please take a look?
thanks...
<html>
<head><title>Object object</title>
<script type="text/javascript">
var Car = {
make:undefined,
year:2006,
price:undefined,
owner : {
name:"Henry Lee",
cell_phone:"222-222-2222",
address: {street:"10 Main",
city:"SF",
state:"CA"
},
dealer:"SF Honda",
display: function() {details="Make: "+Car.make+"\n";
details += "Year:"+Car.year+"\n";
alert(details);
}
}
};
</script>
</head>
<body bgColor="#EOFFFF">
<script type="text/javascript">
Car.make="Honda Civic";
Car.year=2009;
Car.display();
</script>
</body>
</html>
make it
window[Car.display].apply( );
check this
http://stackoverflow.com/questions/676721/calling-dynamic-function-with-dynamic-parameters-in-javascript
window[Car.display].apply(
check this
http://stackoverflow.com/questions/676721/calling-dynamic-function-with-dynamic-parameters-in-javascript
ASKER
@ Proculopsis - that worked however I don't understand since the display method is a property of Car not owner?
owner : {
name:"Henry Lee",
cell_phone:"222-222-2222",
address: {street:"10 Main",
city:"SF",
state:"CA"
}
owner : {
name:"Henry Lee",
cell_phone:"222-222-2222",
address: {street:"10 Main",
city:"SF",
state:"CA"
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Car.owner.display()