Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,20 @@
|
|||
# Lightweight JS objects (with CS sugar).
|
||||
point =
|
||||
x: 5
|
||||
y: 3
|
||||
|
||||
console.log point.x, point.y # 5 3
|
||||
|
||||
# Heavier OO style
|
||||
class Point
|
||||
constructor: (@x, @y) ->
|
||||
distance_from: (p2) ->
|
||||
dx = p2.x - @x
|
||||
dy = p2.y - @y
|
||||
Math.sqrt dx*dx + dy*dy
|
||||
|
||||
p1 = new Point(1, 6)
|
||||
p2 = new Point(6, 18)
|
||||
console.log p1 # { x: 1, y: 6 }
|
||||
console.log p1.distance_from # [Function]
|
||||
console.log p1.distance_from p2 # 13
|
||||
Loading…
Add table
Add a link
Reference in a new issue