Skip to content

Instantly share code, notes, and snippets.

@Sinewyk
Created June 20, 2015 11:34
Show Gist options
  • Save Sinewyk/9466b478d7003268c83b to your computer and use it in GitHub Desktop.
Save Sinewyk/9466b478d7003268c83b to your computer and use it in GitHub Desktop.
No more classes only proxy to functional stuff
/**
* Functional is always better. Keep it simple, just proxy them to classes if you need
* Classes sucks. Try to avoid them.
* Always give a way to use something "class specific" to others
* => don't make it class specific in the first place
* /
function Foo(x) {
this.x = x;
}
// bad
Foo.prototype.squared = function() {
return this.x * this.x;
}
// OR
Foo.prototype.squared = function() {
this.x = this.x * this.x;
return x;
}
// better
// this lives "somewhere", you have commonjs and amd, deal with it.
function square(x) {
return x * x;
}
Foo.prototype.squared = function() {
return square(this.x);
}
// OR
Foo.prototype.squared = function() {
this.x = square(this.x);
return this.x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment