This file contains hidden or 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
#this is the coffeescript with method overloading | |
class User | |
find: (id) -> | |
console.log "find by id" | |
find: (first, last) -> | |
console.log "find by first and last name" | |
class NewUser extends User |
This file contains hidden or 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
# Syntax for private methods in CoffeeScript | |
class Test | |
publicMethod: -> | |
alert @foo | |
private | |
foo: "hello world!" | |
privateMethod -> | |
"private" |
This file contains hidden or 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
class Users | |
find: (id) -> | |
# find user by id | |
find: (first, last) -> | |
# find user by first and last name |
This file contains hidden or 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
/* | |
* is.js | |
* Function that returns whether an object is of a given type. | |
* Pass multiple types to test whether an object is of any of the types | |
* Originally by Dmitry Baranovskiy | |
* Modified by Devon Govett to support multiple types | |
*/ | |
function is(o /*, type, type */) { | |
var types = Array.prototype.slice.call(arguments, 1); |
This file contains hidden or 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
Employee = new db.Model(function() { | |
this.key("name", String, { required: true }); | |
this.key("email", String); | |
this.hasMany("Office"); | |
}) |
This file contains hidden or 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
// #1. Standard hash, but with relationships defined outside of that hash | |
db.define('Employee', { | |
name: Record.type('String').required(), | |
employee_number: Record.type('Number').defaultValue(123) | |
}) | |
Employee.hasOne('Office') |
This file contains hidden or 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
__hasProp: true | |
yearsOld: {max: 10, ida: 9, tim: 11} | |
ages: for child, age of yearsOld | |
child + " is " + age | |
# compiles into this JavaScript, which will not work | |
var _a, _b, age, ages, child, yearsOld; | |
var __hasProp = Object.prototype.hasOwnProperty; | |
__hasProp = true; |
This file contains hidden or 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
class Animal | |
move: (meters) -> | |
alert @name + " moved " + meters + "m." | |
class Snake extends Animal | |
constructor: (name) -> | |
@name: name | |
move: (distance) -> | |
alert "Slithering..." |
This file contains hidden or 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
/* | |
Render SVG Arc with canvas commands | |
Usage: solveArc(x, y, coords) | |
*/ | |
function solveArc(x, y, coords) { | |
var rx = coords[0] | |
var ry = coords[1] | |
var rot = coords[2] | |
var large = coords[3] |
This file contains hidden or 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
/* | |
Path parser by Devon Govett | |
Input: String path | |
Returns: Array of objects with command and arguments | |
*/ | |
//Number of allowed parameters for each command | |
var parameters = { | |
A: 7, | |
a: 7, |