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
// Sometimes you'll need a value type; for representing a point, or other values | |
// which are fully defined after construction. If we take the example of a point: | |
class Point { | |
constructor(public x: number, public y: number) { | |
return Object.freeze(this); | |
} | |
} | |
let p = new Point(3, 4); |
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
this.iter = function iter(array) { | |
var copy = array.slice(); | |
var i = 0; | |
var max = copy.length - 1; | |
var next = function next() { | |
var index = i | |
i += 1 | |
if (index > max) { |
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
function parseHeader(letters: string): number { | |
function letterValue(letter: string): number { | |
return parseInt(letter, 36) - 9 | |
} | |
let result = 0 | |
let factor = 1 | |
if (letters.length === 1) { | |
result = letterValue(letters[0]) |
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
Array.prototype.contains = function(element) { | |
return this.indexOf(element) !== -1; | |
}; |
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
function hasClass(element, class_name) { | |
return element.classList.contains(class_name); | |
} | |
function addClass(element, class_name) { | |
if (!hasClass(element, class_name)) { | |
element.classList.add(class_name) | |
}; | |
} |
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
function KeyboardController(keys, repeat) { | |
var timers = {}; | |
document.addEventListener('keydown', function(event) { | |
var key = event.keyCode; | |
if (!(key in keys)) | |
return true; | |
if (!(key in timers)) { | |
timers[key] = null; | |
keys[key](event); |
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
function augment(obj, function_name, new_function) { | |
var original = obj[function_name]; | |
obj[function_name] = function () { | |
new_function.bind(this, original).apply(this, arguments); | |
original.bind(this).apply(this, arguments); | |
}; | |
} |
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
Array.prototype.remove = function (element) { | |
while (this.contains(element)) { | |
this.splice(this.indexOf(element), 1); | |
} | |
} |
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
window.assert = function assert(condition) { | |
if (!condition) { | |
debugger; | |
}; | |
}; |
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
window.call_super = function call_super(obj, name) { | |
var super_class = Object.getPrototypeOf(Object.getPrototypeOf(obj)); | |
return (function () { | |
super_class[name].apply(obj, arguments); | |
}) | |
} |
OlderNewer