You've almost got it, just replace
withCode:name : "Jacob Michael Perkins";
and it'll work like a charm.Code:name : "Jacob Michael Perkins",
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
Last edited by jp504; 20 Mar 2011 at 12:51 PM. Reason: clarify
You've almost got it, just replace
withCode:name : "Jacob Michael Perkins";
and it'll work like a charm.Code:name : "Jacob Michael Perkins",