Function Wrapping in CoffeeScript - Revisted
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'