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 an example in a post about private members in CoffeeScript. | |
# Read more: http://evanhahn.com/?p=1126 | |
class Sorcerer | |
constructor: (@spell) -> | |
conjureSpell = -> # private | |
@spell.conjure() | |
useSpell: -> | |
conjureSpell.call(this) | |
@spell.use() |
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 an example in a post about private members in CoffeeScript. | |
# Read more: http://evanhahn.com/?p=1126 | |
class Sorcerer | |
conjureSpell = null | |
constructor: (@spell) -> | |
conjureSpell = => # private | |
@spell.conjure() | |
useSpell: -> | |
conjureSpell() |
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 an example in a post about private members in CoffeeScript. | |
# Read more: http://evanhahn.com/?p=1126 | |
class Sorcerer | |
that = null | |
constructor: (@spell) -> | |
that = this | |
conjureSpell = -> # private | |
that.spell.conjure() | |
useSpell: -> |
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 an example in a post about private members in CoffeeScript. | |
# Read more: http://evanhahn.com/?p=1126 | |
class Sorcerer | |
that = null | |
constructor: (@spell) -> | |
that = this | |
conjureSpell = -> # private | |
that.spell.conjure() # Note this hack | |
useSpell: -> |
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 an example in a post about private members in CoffeeScript. | |
# Read more: http://evanhahn.com/?p=1126 | |
class Sorcerer | |
constructor: (@spell) -> | |
conjureSpell = -> # private | |
@spell.conjure() | |
useSpell: -> | |
conjureSpell.call(this) # Note this little hack | |
@spell.use() |
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
# There's more complexity to this, as described below: | |
# http://evanhahn.com/?p=1126 | |
class Person | |
hello = -> | |
"hello" | |
helloWorld: -> | |
"#{hello()} world!" | |
me = new Person |
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
// JavaScript sleepsort | |
// by Evan Hahn (evanhahn.com) | |
// Port of this genius on 4chan: | |
// http://dis.4chan.org/read/prog/1295544154 | |
// Call it like this: | |
// sleepsort(5, 4, 12, 8, 9, 10, 240); | |
function sleepsort() { |
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
var tagsStripped = str.replace(/<[^>]*>/g, ''); |
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
# Make console methods no-ops in unsupported browsers, terse | |
# More versions: <http://evanhahn.com/?p=990> | |
noop = -> | |
window.console || (window.console = {}) | |
window.console.error || (window.console.error = noop) | |
window.console.info || (window.console.info = noop) | |
window.console.log || (window.console.log = noop) | |
window.console.warn || (window.console.warn = noop) |
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
# Make console methods no-ops in unsupported browsers, complete | |
# More versions: <http://evanhahn.com/?p=990> | |
noop = -> | |
window.console || (window.console = {}) | |
window.console.assert || (window.console.assert = noop) | |
window.console.clear || (window.console.clear = noop) | |
window.console.count || (window.console.count = noop) | |
window.console.debug || (window.console.debug = noop) | |
window.console.dir || (window.console.dir = noop) |