Created
January 20, 2023 18:35
-
-
Save alphanetEX/ea14b9500d6530e586e0d6ce6f968389 to your computer and use it in GitHub Desktop.
secondPrototypeworks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
//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.NewAtributes = function(){ | |
console.log(`${this.nroFrabrication}`); | |
} | |
let mercedes = new Car("mercedes", "sl-500", "sedan", 2019 ,"Gray"); | |
let typeObject1 = Object.getPrototypeOf(mercedes); | |
typeObject1.nroFrabrication = `POINTER-06`; | |
typeObject1.PATENT = "JS-02A"; | |
typeObject1.TURBO = false; | |
let toyota = new Car("toyota", "corolla", "sedan", 2015, "red"); | |
Car.prototype = { | |
PATENT : `BPX-02A`, | |
INTERNAL: `ITNX-01A`, | |
aproved : function(patent){ | |
console.log(`the status of car ${this.brand} with ${this.INTERNAL} its aproved`); | |
} | |
}; | |
typeObject1.Turbo = function(){ | |
this.TURBO = true; | |
console.log(`the ${this.model.toUpperCase()} was enabled: ${this.TURBO}`); | |
} | |
let formula1 = new Car("redbull", "rb-22", "formula", 2021, "blue-dark"); | |
//acediendo a los objetos de constructor `car` | |
console.log(mercedes.year); | |
mercedes.motor("bcv-8", true, 445, 8); | |
mercedes.gearbox("gcv500", true, "500cv"); | |
mercedes.newAtributes(); | |
toyota.newAtributes(); | |
toyota.turbo(); | |
// formula1.newAtributes(); | |
formula1.aproved(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment