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
SurveyTimersPage.prototype.updateTimerQuestionResponse = function () { | |
var newResponseId = null; | |
if (this.timerMgr.hasValuesEntered()) { | |
// Update this questions response to the timer measurement response. | |
var resp = this.surveyMgr.getCorrectResponse(this.timerQuestion.AllowableValues); | |
if (resp !== null) { | |
newResponseId = resp.id; |
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
// The quick and dirty way | |
var baby1 = { | |
name: "cutesy", | |
sex: "F", | |
speak: function() { | |
return "gaga"; // As in Lady | |
} | |
}; | |
// Functionally equivalent to this... |
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
// The classical prototype way | |
/* Define a constructor */ | |
function Baby(name, sex, says) { | |
// Set some variables on the object | |
this.name = name; | |
this.sex = sex; | |
this.says = says; | |
} |
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 highlightMenu() { | |
// Find my the current menu item and highlight it... | |
}; | |
function loadWizzyMathinger() { | |
// Load the almighty Wizzy Mathinger | |
}; | |
function handleItemClick(evt) { |
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
// pages.Page1.js | |
// I like to include the file name at the top in case we ever concatenate our scripts and need to find this file to debug. | |
// Wrap each block of code in a self executing function. | |
// At the bottom, we pass in these objects to this function and immediately execute it. | |
(function($, window, document) { | |
"use strict"; | |
// Optionally, a single string "use strict" will force strict mode and help you catch common javascript errors before they get into the wild. | |
// Pass in jQuery and the window object to protect from other people messing with their values. |
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
DisposableView = Backbone.View.extend({ | |
modelUnbindAll: function() { | |
var modelOrCollection = this.model || this.collection; | |
if (modelOrCollection) { | |
modelOrCollection.off(null, null, this); | |
} | |
}, |
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
_when = (proms..., cb) -> | |
def = newPromise() | |
promCount = proms.length | |
finishProm = -> | |
promCount-- | |
# May be -1 here... | |
unless promCount > 0 | |
def.resolve() |
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
isMult = (num, mult) -> (num % mult) is 0 | |
isMult3 = (num) -> isMult num, 3 | |
isMult5 = (num) -> isMult num, 5 | |
fizzBuzz = (min = 0, max = 100) -> | |
output = (num) -> | |
is3 = isMult3 num | |
is5 = isMult5 num | |
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
arraysEqual = (nums1, nums2) -> | |
# Check the length | |
return false unless nums1.length == nums2.length | |
# Sort the arrays | |
nums1.sort() | |
nums2.sort() | |
# A helper for checking indices are same |
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
// Some basic javascript Date examples | |
// NOTE: Javascript dates have 0 indexed months, because they are awesome | |
// January 1, 2012 (Chicago, IL) | |
var firstOfYear = new Date(2012, 0, 1), | |
// 6 Hour offset (before DST change) | |
hoursOffset = firstOfYear.getTimezoneOffset() / 60; | |
// April 1, 2012 (Chicago, IL) |