branch14log

Function Wrapping in CoffeeScript - Revisted

19 Jul 2012

Some days ago I was writing about function wrapping in CoffeeScript as a general pattern to built upon existing code. Here is a slightly better version which will also work with an arbitrary amount of function parameters.
class MyClass
  myMethod: (name, surname) ->
    console.log "hello #{name}"
    
# function wrapping
MyClass::myMethod = ((_super) ->
  (_args...) ->
    _super.apply this, _args
    [name, surname] = _args
    console.log "bye Mister #{surname}"
)(MyClass::myMethod)

(new MyClass).myMethod 'Falko', 'Schmidt'