Fix to allow virtual methods without parameters #41

Merged
merged 1 commit into from Apr 23, 2012

Projects

None yet

2 participants

@grahamlyus
Contributor

Was getting Get method signature error: undefined [TypeError: Cannot read property 'length' of undefined] when using @method to declare a method without parameters. This fixes it by making getParameters return an empty array in that case.

I came across this when trying to figure out a way to document my own type of 'mixin' that is returned by an instance method, e.g.

class Com.Example.Aspect
  mixins: =>
    # Does something interesting.
    aMixedInMethod: =>
      @somePrivateMethod()

  # @private
  somePrivateMethod: () =>
    # do something.

The documentation for the methods in mixins is ignored. I'd tried using a @mixin tag, but that didn't help, so I ended up going with:

# @method #aMixedInMethod
#   Does something interesting.
class Com.Example.Aspect
  mixins: =>
    aMixedInMethod: =>
      @somePrivateMethod()

  # @private
  somePrivateMethod: () =>
    # do something.

I'd rather find some way of having the doc tags alongside the method if at all possible, if you have any ideas?

@netzpirat netzpirat merged commit 806b053 into coffeedoc:master Apr 23, 2012
@netzpirat
Contributor

Thanks for the fix. Currently mixins are only detected when they are defined as variables and not methods. It's certainly possible to also detect method mixins by looking at the docstring for methods and create a new mixin instead pushing it to the methods of the class when the docs contains a @mixin tag.

@grahamlyus
Contributor

It seems maybe what I want is if I tag a method with @mixin to just add the returned methods from that method to the class.

@netzpirat
Contributor

But what's the reason of getting the methods to mix into another class from a function instead a variable? Do you have dynamic (factory) mixins?

@grahamlyus
Contributor

Yes, they are dynamic and included at run time, but also need to retain their own 'this', hence the bound mixins function. The object that includes them is usually passed to the constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment