Ricky Sharma
Ricky Sharma

Reputation: 1919

What exactly Javascript prototype is? A library or something builtin Javascript?

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.

Upvotes: 2

Views: 4246

Answers (3)

Barmar
Barmar

Reputation: 780889

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

Upvotes: 5

Odai Al-Ghamdi
Odai Al-Ghamdi

Reputation: 302

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

Upvotes: 0

HMR
HMR

Reputation: 39260

  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.

Upvotes: 2

Related Questions