Results 1 to 2 of 2

Thread: Problems with JavaScript Object literal Notation

  1. #1
    Join Date
    Oct 2010
    Posts
    37

    Problems with JavaScript Object literal Notation

    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

  2. #2
    Join Date
    Mar 2011
    Location
    Palm Beach
    Posts
    12
    You've almost got it, just replace
    Code:
    name : "Jacob Michael Perkins";
    with

    Code:
    name : "Jacob Michael Perkins",
    and it'll work like a charm.

Similar Threads

  1. reformat javascript date object?
    By kenw232 in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 13 Jan 2011, 10:59 AM
  2. javascript "expects object"
    By speedy_rudolf in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 01 Oct 2009, 01:04 PM
  3. Object instance doesnt point to object?
    By Slippy in forum General Questions
    Replies: 0
    Last Post: 31 May 2008, 06:32 PM
  4. Problems with OBJECT tag linking in IE
    By RevThwack in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 03 Nov 2005, 11:52 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •