www.webdeveloper.com
Results 1 to 4 of 4

Thread: Prototype meaning

  1. #1
    Join Date
    Nov 2011
    Posts
    64

    Prototype meaning

    When I reading a script, I encounter a word called "Prototype". Can someone help explain what it means in javascript?

  2. #2
    Join Date
    Nov 2011
    Posts
    64
    Code:
    <script>function Foo()
    {
        this.x = 1;
    }
    Foo.prototype.AddX = function(y)    // Define Method
    {
        this.x += y;
    }
    obj = new Foo;
    obj.AddX(5);    
    </script>
    The above code doesn't work?

  3. #3
    Join Date
    Apr 2012
    Posts
    55
    The prototype property of a constructor is used for object inheritance. Are you familiar with object oriented programming? Most languages use classes for inheritance, but JavaScript doesn't have classes -- it has prototypes instead.

    The script you posted seems to work fine to me. Are you having trouble with it? It's a good example for someone new to the prototype property.
    joi JavaScript Framework - the sunnier side of JavaScript.

  4. #4
    Join Date
    Nov 2011
    Posts
    64
    "Class" I saw it in PHP. Is it of similar function? I think I got the code working already.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles