Skip to content

Instantly share code, notes, and snippets.

@KamilaBorowska
Created April 22, 2012 15:01
Show Gist options
  • Save KamilaBorowska/2464490 to your computer and use it in GitHub Desktop.
Save KamilaBorowska/2464490 to your computer and use it in GitHub Desktop.
Proper JavaScript classes
function makePoint(x, y) {
"use strict";
return {
x: x,
y: y,
distanceTo: function (point) {
var dx = this.x - point.x,
dy = this.y - point.y;
return Math.sqrt(dx * dx + dy * dy);
}
};
}
// No new
var points = [
makePoint(9, 12),
makePoint(3, 4)
];
console.log(points[0].distanceTo(points[1]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment