let x = {}
let x = new Object();
let y = Object.create(x)
Class-based
Constructor Function
Factory function
function Constructor(name, age) {
this.name = name;
this.age = age;
this.ten = function() {
return `Ten: ${this.name}`
}
this.tuoi = function() {
return `Tuoi ${this.tuoi}`
}
}
const p = new Constructor("Hoc co ban",10);
console.log(p.ten());
function Factory(name, age) {
let private = 100;
function ten() {
return "Ten: " + name;
}
function tuoi() {
return "Tuoi: " + age;
}
return {
ten: ten,
tuoi: tuoi,
data: private
}
}
const mot = Factory("abcd",1);
console.log(mot.ten());
console.log(mot.data);