Skip to content

Instantly share code, notes, and snippets.

@getify getify/ex1.js
Last active May 25, 2019

Embed
What would you like to do?
class vs OLOO
class Foo {
constructor(x,y,z) {
Object.assign(this,{ x, y, z });
}
hello() {
console.log(this.x + this.y + this.z);
}
}
var instances = [];
for (var i=0; i<500; i++) {
instances.push(
new Foo(i,i*2,i*3)
);
}
instances[37].hello(); // 222
var Foo = {
hello() {
console.log(this.x + this.y + this.z);
}
};
function OD(prot,obj) { return Object.assign(Object.create(prot),obj); }
var instances = [];
for (var i=0; i<500; i++) {
instances.push(
OD(Foo,{ x: i, y: i*2, z: i*3 })
);
}
instances[37].hello(); // 222
function Foo(x,y,z) {
return {
hello() {
console.log(this.x + this.y + this.z);
},
x,
y,
z
};
}
var instances = [];
for (var i=0; i<500; i++) {
instances.push(
Foo(i,i*2,i*3)
);
}
instances[37].hello(); // 222
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.