Skip to content

Instantly share code, notes, and snippets.

@EvanHahn
Created August 15, 2012 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvanHahn/3364322 to your computer and use it in GitHub Desktop.
Save EvanHahn/3364322 to your computer and use it in GitHub Desktop.
Inheriting private member functions working in CoffeeScript, with .call()
# 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()
class Child extends Sorcerer
constructor: (@spell) -> # Overriding the constructor
c = new Child
conjure: -> console.log "Brewing potion..."
use: -> console.log "Now I have superpowers!"
c.useSpell()
# This code by Evan Hahn (evanhahn.com) is licensed under the Unlicense.
# http://unlicense.org/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment