Skip to content

Instantly share code, notes, and snippets.

@Aleksey-Danchin
Created October 21, 2016 10:34
Show Gist options
  • Save Aleksey-Danchin/a88ba72ffbd2f5c9bbdf24f760959910 to your computer and use it in GitHub Desktop.
Save Aleksey-Danchin/a88ba72ffbd2f5c9bbdf24f760959910 to your computer and use it in GitHub Desktop.
Пример реализации цепного стиля программирования.
class Point {
constructor () {
const point = this;
point.x = 0;
point.y = 0;
point.color = 'red';
}
moveTo (x, y) {
const point = this;
point.x = x;
point.y = y;
return point;
}
setColor (color) {
const point = this;
point.color = color;
return point;
}
draw () {
const point = this;
console.log(`Point of (${point.x};${point.y}) position and '${point.color}' color drawed!`);
return point;
}
}
const point = new Point;
point.moveTo(100, 200)
.setColor('red')
.draw();
// Point of (100;200) position and 'red' color drawed!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment