Skip to content

Instantly share code, notes, and snippets.

@batogov
Created October 1, 2017 19:53
Show Gist options
  • Save batogov/dc4c064ca2e5f646c7ad4d103c2495f3 to your computer and use it in GitHub Desktop.
Save batogov/dc4c064ca2e5f646c7ad4d103c2495f3 to your computer and use it in GitHub Desktop.
Использование "OLOO" (objects-linked-to-other-objects) стиля
/* POINT */
var Point = {
init: function(x, y) {
this.x = x;
this.y = y;
},
move: function(deltaX, deltaY) {
this.x += deltaX;
this.y += deltaY;
}
}
/* POINT WITH NAME */
var PointWithName = Object.create(Point);
PointWithName.initWithName = function(x, y, name) {
this.init(x, y);
this.name = name;
}
/* CREATE OBJECTS */
var p = Object.create(Point);
p.init(10, 10);
p.move(-2, -2);
var pWithName = Object.create(PointWithName);
pWithName.initWithName(5, 5, 'Awesome Name!');
pWithName.move(-5, -5);
console.log(p);
console.log(pWithName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment