+ 2

JS Prototype

I don’t really understand why to use prototype. The understanding that I have of it so far it's that you can call an objects properties (like "this. ") outside of it's scope

23rd Apr 2018, 2:07 PM
Ole113
Ole113 - avatar
5 odpowiedzi
+ 2
A prototype is basically the class structure for JavaScript. That changed in the latest versions to actually be a Class call. But in ES5 that browsers use we're stuck with the prototype format.
23rd Apr 2018, 2:43 PM
Adam
Adam - avatar
+ 2
Javascript is a language based on prototypes... This mean that all is based on description called prototype (functions, objects etc)... Its not simple explain (for me) then i post a link that i hope help you understand: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain
23rd Apr 2018, 2:12 PM
KrOW
KrOW - avatar
+ 1
But why would you use for example car.prototype?
23rd Apr 2018, 2:47 PM
Ole113
Ole113 - avatar
0
Why would you use Class Car() in any other language? Because your project deals with a number of cat related things repeatedly so it becomes easier to create a prototype of car in your local javascript.
23rd Apr 2018, 4:20 PM
Adam
Adam - avatar
0
Think of it like this. A prototype of a physical product is the first time it has been made with its official specs m defined. In javascript, a prototype is the definition of all the aspects of a thing. so car.prototype defines all the parameters methods and variables for a car. Just as class Car() does the same. It is literally just a word change. Then you instantiate it with new Car() in us. prototype is the same as class. Newer versions of javascript have changed prototype for class so the language matches others. But browsers only go up to ES5.
8th May 2018, 4:41 PM
Adam
Adam - avatar