Created
October 21, 2016 10:34
-
-
Save Aleksey-Danchin/a88ba72ffbd2f5c9bbdf24f760959910 to your computer and use it in GitHub Desktop.
Пример реализации цепного стиля программирования.
This file contains hidden or 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 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