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 SortableList | |
constructor: (el) -> | |
@el = $(el) | |
down: (e) => | |
e.preventDefault() | |
top = @el.offset().top | |
@el.find(".sortable").each (i, el) -> | |
$el = $(el) | |
offset = $el.offset().top |
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
pathological.js: line 1, col 17, Wrap an immediate function invocation in parentheses to assist the reader in understanding that the expression is the result of a function, and not the function itself. | |
pathological.js: line 1, col 17, Expected an assignment or function call and instead saw an expression. | |
pathological.js: line 2, col 17, Move the invocation into the parens that contain the function. |
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
$.poll({ | |
url: '/status.json' | |
, dataType: 'json' | |
, timeout: 1000 // initial timeout of 1s | |
, multiplier: 2 // double the timeout each time | |
, retries: 10 // maximum of ten tries | |
, until: function(data) { return data.status == 'done'; } | |
, success: function(data) { alert(data.message); } | |
}); |
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 Messages extends Spine.Controller | |
constructor: -> | |
super | |
@el.addClass("messages") | |
@appendTo "body" | |
send: (str) -> | |
@append(new Message({ message: str })) | |
@instance: -> |
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
Number::pad = (digits, signed) -> | |
s = Math.abs(@).toString() | |
s = "0" + s while s.length < digits | |
(if @ < 0 then "-" else (if signed then "+" else "")) + s | |
Date.months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ] | |
Date.weekdays = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ] | |
Date.formats = | |
"a": -> Date.weekdays[@getDay()].substring(0, 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
<div id="the_div"> | |
<ul id="the_list"> | |
<li id="the_item">Click me!</li> | |
</ul> | |
</div> | |
<p id="log"></p> | |
<script type="text/javascript" charset="utf-8"> | |
function log(string){ |
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. Write a class to support the following code: | |
function Person(name) { | |
this.name = name; | |
} | |
var thomas = new Person('Thomas'); | |
var amy = new Person('Amy'); | |
thomas.name // --> "Thomas" |
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
Function.prototype.cached = function() { | |
var f = this, | |
cache = {}; | |
function get(c, a, i) { | |
var l = a.length, k = a[i]; | |
if (l == 0) { | |
return f(); | |
} else if (i==l) { | |
return (k in c) ? c[k] : (c[k] = f.apply(this, a)); |
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
function logCar(options) { | |
if (options.hasOwnProperty('make') && options.hasOwnProperty('color')) { | |
console.log("I'm a " + options.color + " " + options.make); | |
} else { | |
console.log("Please supply make and color!"); | |
} | |
} | |
function Car(make, color) { | |
this.make = make; |
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
// Exercise 2 - Closures | |
// Wrap the following code in a closure and export only the "countdown" function. | |
(function(scope, functionName) { | |
var index; | |
function log(){ | |
console.log(index); | |
} |