new tasks
This commit is contained in:
parent
2a4d27cea0
commit
80737d5a6a
1194 changed files with 15353 additions and 1 deletions
4
Task/Delegates/CoffeeScript/delegates-2.coffee
Normal file
4
Task/Delegates/CoffeeScript/delegates-2.coffee
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
> coffee foo.coffee
|
||||
default implementation
|
||||
default implementation
|
||||
Delegate Implementation
|
||||
24
Task/Delegates/CoffeeScript/delegates.coffee
Normal file
24
Task/Delegates/CoffeeScript/delegates.coffee
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
class Delegator
|
||||
operation: ->
|
||||
if @delegate and typeof (@delegate.thing) is "function"
|
||||
return @delegate.thing()
|
||||
"default implementation"
|
||||
|
||||
class Delegate
|
||||
thing: ->
|
||||
"Delegate Implementation"
|
||||
|
||||
testDelegator = ->
|
||||
# Delegator with no delegate.
|
||||
a = new Delegator()
|
||||
console.log a.operation()
|
||||
|
||||
# Delegator with delegate not implementing "thing"
|
||||
a.delegate = "A delegate may be any object"
|
||||
console.log a.operation()
|
||||
|
||||
# Delegator with delegate that does implement "thing"
|
||||
a.delegate = new Delegate()
|
||||
console.log a.operation()
|
||||
|
||||
testDelegator()
|
||||
Loading…
Add table
Add a link
Reference in a new issue