This file contains 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
// How do you tend to declare variables in your code, when nested in an if / else? | |
// All three are functionally equivalent. | |
// (Ternary is cheating for these purposes.) | |
// Option 1: | |
function() { | |
if (condition) { | |
var attrs = a; | |
} else { |
This file contains 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
// Take the symmetric difference between a list of arrays. Only the elements | |
// present in one of the input arrays will remain. | |
_.symDifference = function() { | |
return _.reduce(arguments, function(memo, array) { | |
return _.union(_.difference(memo, array), _.difference(array, memo)); | |
}); | |
}; |
This file contains 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
dc.ui.AnnotationEditor = Backbone.View.extend({ | |
id : 'annotation_editor', | |
events : { | |
'click .close': 'close' | |
}, | |
constructor : function(options) { | |
Backbone.View.call(this, options); |
This file contains 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
// Demonstration of dynamic super() calls. | |
// Because of JS reserved words, "ssuper()" is the method name, | |
// and is passed the current object, as well as the name of | |
// the current method. | |
function GreatGrandParent() {}; | |
GreatGrandParent.prototype.method = function() { | |
console.log("In the GreatGrandParent."); | |
}; |
This file contains 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
// Here is a proposal for minimalist JavaScript classes, humbly offered. | |
// There are (at least) two different directions in which classes can be steered. | |
// If we go for a wholly new semantics and implementation, then fancier classical | |
// inheritance can be supported with parallel prototype chains for true inheritance | |
// of properties at both the class and instance level. | |
// If however, we keep current JavaScript prototype semantics, and add a form that | |
// can desugar to ES3, things must necessarily stay simpler. This is the direction | |
// I'm assuming here. |
This file contains 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
// From: https://mail.mozilla.org/pipermail/es-discuss/2011-October/thread.html#17696 | |
const className = superClass <| function(/*constructor parameters */) { | |
//constructor body | |
super.constructor(/*arguments to super constructor */); | |
this.{ | |
//per instance property definitions | |
}; | |
}.prototype.{ | |
//instance properties defined on prototype |
This file contains 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
insert: (ball, column) -> | |
for row in @rows when row[column] is null | |
row[column] = ball | |
return |
This file contains 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
if a | |
if b | |
if c | |
d | |
e | |
f |
This file contains 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
dc.ui.Document = Backbone.View.extend({ | |
initialize: function() { | |
this.model.bind('change', this._onDocumentChange); | |
this.model.bind('change:selected', this._setSelected); | |
this.model.bind('view:pages', this.viewPages); | |
this.model.notes.bind('add', this._addNote); | |
this.model.notes.bind('reset', this._renderNotes); | |
this.model.pageEntities.bind('reset', this._renderPages); | |
} |
This file contains 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
highlightWord = (node, word) -> | |
if node.hasChildNodes | |
children = node.childNodes | |
highlightWord(item, word) for item in children | |
if node.nodeType == 3 | |
tempNodeVal = node.nodeValue.toLowerCase() | |
tempWordValue = word.toLowerCase() | |