Skip to content

Instantly share code, notes, and snippets.

@adityardiansyah
Created January 15, 2020 14:51
Show Gist options
  • Save adityardiansyah/b8b16bee2e51e68804a0099dc6faa843 to your computer and use it in GitHub Desktop.
Save adityardiansyah/b8b16bee2e51e68804a0099dc6faa843 to your computer and use it in GitHub Desktop.
Object Create ini kelebihannya adalah otomatisasi method dan mempersimpel code
// Object Create
const methodSaya = {
makan: function (porsi) {
this.energi += porsi;
},
main: function (jam) {
this.energi -= jam;
}
}
function Saya(nama, energi) {
let saya = Object.create(methodSaya);
saya.nama = nama;
saya.energi = energi;
return saya;
}
let aku = Saya('Aditya', 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment