Skip to content

Instantly share code, notes, and snippets.

@alphanetEX
Created January 20, 2023 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alphanetEX/5621e7333157e0d0d738c9913e51850c to your computer and use it in GitHub Desktop.
Save alphanetEX/5621e7333157e0d0d738c9913e51850c to your computer and use it in GitHub Desktop.
prototype code schematic
"use strict";
global.alphanet = `alphanet`;
//aplciando closure
function makeMoney(){
let gcant=0
return {
//this apuntara a lo que este dentro de este objeto
saveMoney: function(cant){
return (gcant+=+cant);
},
soldMoney: function(cant){
return (gcant-=+cant);
},
showCant: function(){
return `the actual money its= ${gcant}`
}
}
}
// let alphanet = makeMoney();
// console.log(alphanet.showCant());
// alphanet.saveMoney(10);
// alphanet.saveMoney(20);
// console.log(alphanet.showCant());
//use prototype
let barist={
name: "emmanuel",
type: "barist",
encode: "pointer this U0X",
prepareCoffe: function(){
console.log(`preparing dopio cortado ristreto`);
}
}
let developer = {
name: "Anderson",
alias: "AlphanetEX",
type: "BackendDev",
developent: function(){
console.log("creating guide of depth JS");
}
}
//not recomendable application
// developer.__proto__ = barist;
//establecerle un prototipo al objeto
Object.setPrototypeOf(developer, barist)
barist.createV60 = function(variant){
console.log(`creating V60 with varietal ${variant} and the barist its ${this.name}`);
}
developer.typeOS = function(OS){
console.log(`the developer was starter using code with ${OS}`);
console.log(`enabling encode: ${this.encode}`);
}
console.log(developer.prepareCoffe());
console.log(developer.createV60("El Salvador"));
console.log(developer.typeOS("Linux"));
console.log(developer.type);
//clase basada en objetos prototipales
function car(brand, model, type, year, color ){
this.brand = brand;
this.model = model;
this.type = type;
this.year = year;
this.color = color;
};
//esta variable es guardada dentro del objeto protoype
car.prototype.PATENT= "000X-01X";
car.prototype.motor = function(model, turbo, CV, pistons){
console.log(`${this.model}, max cv of motor ${CV}`);
}
car.prototype.gearbox = function(model, gears, maxtorq) {
console.log(`${this.model}, cant of gears ${gears}`);
};
car.prototype.globalx = ()=>{
console.log(this.brand);
}
let mercedes = new car("mercedes", "sl-500", "sedan", "Gray");
let typeObject1 = Object.getPrototypeOf(mercedes);
//acediendo a los objetos de constructor `car`
console.log(mercedes.year);
mercedes.globalx();
mercedes.motor("bcv-8", true, 445, 8);
mercedes.gearbox("gcv500", true, "500cv");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment