2

I am confused between prototype thing. I have researched and watched tutorials but still I have not been able to get a clear answer. Glad if someone could help me under it. Great if using some simple example or explanation.

  1. Is Prototype a library? e.g. Jquery

    If Yes. That means we need to add it to our file before working with it. Like we add Jquery in head and then we get access to it's functions and all.

    So we need to learn it before using it because prototype is build using the pure javascript like Jquery is.

  2. If Prototype is a Library then how can we access it without even adding to file ?

    For example :- When we are writing some javascript code then we automatically get access to Prototype thing like in this code below.

        function Apple (type) {
        this.type = type;
        this.color = "red";
    }
    

    Apple.prototype.getInfo = function() { return this.color + ' ' + this.type + ' apple'; };

  3. Some people are saying Prototype is actually a Javascript.

    If this is right then how we have prototype and jQuery separated in this list from JSFiddle below. enter image description here

  4. Or is Prototype library like in the image above is different than the Javascript prototype object?

    Means these are 2 different things.

Could you please clarify my these 4 points.

Thank you.

Ricky Sharma
  • 1,839
  • 3
  • 24
  • 44
  • 3
    There is a JavaScript library called "Prototype". The term "prototype" is also used (both descriptively and as part of the runtime system) for a basic mechanism of the programming language. The uses of the terms are only conceptually related, and loosely at that. You can't get around dealing with the "prototype" concept in JavaScript programming, but you absolutely do not have to use the Prototype library. – Pointy Aug 26 '13 at 23:59
  • ^ i support this comment – Shan Robertson Aug 27 '13 at 00:00
  • @Pointy So that means these are 2 different things like I have mentioned in point 4? – Ricky Sharma Aug 27 '13 at 00:01
  • 1
    @RIK yes, point 4 it is. They're two *almost* completely different things. The "Prototype" library (probably) takes its name from the fact that it's based on an implementation approach that exploits the "prototype" language construct. – Pointy Aug 27 '13 at 00:07

3 Answers3

5

It's both.

  1. Javascript has a standard property of objects named prototype, which is used as part of its object-oriented programming mechanism. You can read more about it in this question: How does JavaScript .prototype work?

  2. There's a Javascript framework library called Prototype. You can learn more about it at prototypejs.org

Community
  • 1
  • 1
Barmar
  • 741,623
  • 53
  • 500
  • 612
2
  1. prototype.js is a library that like jQuery makes is easier to register events, select html elements and such.
  2. prototype is also part of standard JavaScript, the code you provided is part of standard JavaScript so you don't need the prototype.js library for that code to work.
  3. Prototype is both a library and standard JavaScript (see answer 1 and 2)
  4. See previous answers

For more info on prototype (standard JS not the library) check this answer.

Community
  • 1
  • 1
HMR
  • 37,593
  • 24
  • 91
  • 160
0

prototype is a javascript library just like Jquery you need to include it into your html file

Odai Al-Ghamdi
  • 302
  • 2
  • 12