Protoype Object

logo_JavaScriptWhat is exactly Prototype? honestly I had tried finger out for a while, but in short word, that is create a model for all product!

Just like if you want product 3 different brand of car, like volve, Ford, audi. Those brand car has something comment, at least they all have: Doors(4 or 2), Mirrors(2), wheels(4) etc. so make prototype means make those comment items if you need a chain industry production.

So you need to make constructor —> define prototype object –> product the car

Let’s see the code:

Capturefirst we get car constructor, inject 3 parameter : wheel, doors and mirror

then we just define car prototype



so here make 2 car brand different, one is volve, the other one is Ford, use new keyword to inherent  the prototype CarObject, inject numbers or any string for define the items. Test out, so we could find volev has 4 wheel, 2 mirror, and Ford has 2 doors, 4 wheels, in this case we do not have to create each car items type just call those prototype!

en conclusion:

function obj() { // construct here }

obj.prototype.model = function() { // prototype model here }

var obj2 = new obj();





Leave a Reply

Your email address will not be published. Required fields are marked *