JSFiddle - React, Tailwind, and code Playground
by shaunxcode
HTML
<script src="http://underscorejs.org/underscore.js"></script>
CoffeeScript
Obj = (odef) ->
self = {}
for name, sdef of odef
self[name] = sdef
for field, val of Obj[name]
do (field, val) ->
if _.isFunction val
self[name][field] = -> val.apply self, arguments
else
if not self[name][field]
self[name][field] = val
self
Obj.Point =
x: 0
y: 0
Obj.Vertice =
tail: false
asLine: ->
console.log @
return if not @Vertice.tail
x1: @Point.x
y1: @Point.y
x2: @Vertice.tail.Point.x
y2: @Vertice.tail.Point.y
a = Obj
Point:
x: 5
y: 10
Vertice: {}
b = Obj
Point:
x: 20
y: 30
Vertice:
tail: a
console.log a, b
console.log a.Point.x
console.log a.Vertice.asLine is b.Vertice.asLine
console.log b.Vertice.asLine()
console.log a.Vertice.asLine()
p = (a, b) -> Obj Point: x: a, y: b
points = []
for x in [1..100]
for y in [1..100]
points.push p x, y
console.log points