Created
October 1, 2017 19:53
-
-
Save batogov/dc4c064ca2e5f646c7ad4d103c2495f3 to your computer and use it in GitHub Desktop.
Использование "OLOO" (objects-linked-to-other-objects) стиля
This file contains 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
/* 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