wenchun / jsdoc-toolkit

Automatically exported from code.google.com/p/jsdoc-toolkit
0 stars 0 forks source link

Prototype.js: initialise(args) is the actual constructor #83

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. generate the Animal/Snake example using branches/version2.0

What is the expected output? What do you see instead?
The constructor is documented as Animal() and the initialise(name,sound) method 
as a function. 
Wouldn't it be more logical to document these as an Animal(name,sound) 
constructor ?

Original issue reported on code.google.com by christop...@gmail.com on 17 Feb 2008 at 12:19

GoogleCodeExporter commented 8 years ago
Logical? Depends on whether initialise is a constructor or not. Is it? Not 
being a
user of Prototype I don't actually know, which is why I posted for feedback on 
this
topic a few weeks ago. Are you asserting that issue() is not a method of Animal?

Original comment by micmath on 17 Feb 2008 at 12:27

GoogleCodeExporter commented 8 years ago
erm, that should be "...asserting that initialise() is not a method of Animal?"

Original comment by micmath on 17 Feb 2008 at 12:30

GoogleCodeExporter commented 8 years ago
From http://www.prototypejs.org/api/class/create ...

"Class.create returns a function that, when called, will fire its own 
initialize method."

Which is why I (possibly mistakenly) thought "initialize" was a method.

Original comment by micmath on 17 Feb 2008 at 12:35

GoogleCodeExporter commented 8 years ago
Given the Animal/Snake example, one would instantiate an Animal using 

var myAnimal = new Animal( "aName", "aSound" );

One could probably also use

var myAnimal = new Animal();
myAnimal.initialize( "aName", "aSound" );

Which supports the current documentation generation.

But it's a shame that the (IMHO) more logical constructor named Animal with 
arguments isn't documented as 
at least a second constructor, which is one of the merits of Prototype.js.

Original comment by christop...@gmail.com on 17 Feb 2008 at 12:37

GoogleCodeExporter commented 8 years ago
I agree. I'll have a look at correcting that.

Original comment by micmath on 17 Feb 2008 at 12:45

GoogleCodeExporter commented 8 years ago
The latest revision of Version 2 allows for the documentation described here:
http://jsdoctoolkit.org/wiki/?page=lends

Unfortunately this breaks the prototype plugin (causes recursion), so that has 
had to
be disabled.

Like so:

var Person = makeClass(
    /**
      @lends Person.prototype
    */
    {
        /** @constructor */
        initialize: function(name) {
            this.name = name;
        },
        say: function(message) {
            return this.name + " says: " + message;
        }
    }
);

Original comment by micmath on 24 Feb 2008 at 12:33

GoogleCodeExporter commented 8 years ago
Michael, you meant "@constructs", not "@constructor", in the previous comment, 
right?
 As of 2.1.0, @constructs seems to work.  @constructor does not.

Original comment by broofa on 18 Feb 2009 at 1:15

GoogleCodeExporter commented 8 years ago
Good spot, Robert, but actually on the 24th of February, 2008, I *did* mean 
"@constructor". However, checking 
the commit logs, I see that on the 25th of February (Revision: 521) the 
following comment was made:

    "Got @property to work, changed lent @constructor back to @constructs."

So, for anyone reading this now, the current solution is indeed @constructs, 
which is the one that actually made 
it into the release.

Original comment by micmath on 19 Feb 2009 at 11:20