Skip to content

Instantly share code, notes, and snippets.

@getify
Created April 11, 2018 12:30
Show Gist options
  • Save getify/6ca9237ecdc4044ac334a40c00f9a1fd to your computer and use it in GitHub Desktop.
Save getify/6ca9237ecdc4044ac334a40c00f9a1fd to your computer and use it in GitHub Desktop.
class (with bound method) vs module
class Foo {
constructor(x) {
this.x = x;
this.hello = () => {
console.log(this.x);
};
}
}
var a = new Foo(12);
a.hello(); // 12
var b = new Foo(20);
b.hello(); // 20
function Foo(x) {
return {
hello() { console.log(x); }
};
}
var a = Foo(12);
a.hello(); // 12
var b = Foo(20);
b.hello(); // 20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment