-
-
Save vvatikiotis/12ccaeb17575135b85393b462a355ca8 to your computer and use it in GitHub Desktop.
class vs OLOO
This file contains 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
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 |
This file contains 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
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 |
This file contains 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
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