jp504
19 Mar 2011, 05:16 PM
Hello. I am a beginner at JavaScript. I am currently practicing JavaScript OOP, and can't get object literal notation to work. I am basically copying and pasting the script, but it still won't work.
Here is a small snippet of code that I can't get to work.
<script type="text/javascript">
var Person = {
name : "Jacob Michael Perkins";
show : function()
{
alert("Your name is " + this.name);
}
}
Person.show();
</script>
What the heck am I doing wrong. OOP using constructor functions work fine, but this won't work at all. Please help. Thanks in advance
Here is a small snippet of code that I can't get to work.
<script type="text/javascript">
var Person = {
name : "Jacob Michael Perkins";
show : function()
{
alert("Your name is " + this.name);
}
}
Person.show();
</script>
What the heck am I doing wrong. OOP using constructor functions work fine, but this won't work at all. Please help. Thanks in advance