I've been trying to document the following code using JSDoc:
/**
* @module person
*/
/**
* A human being.
* @class
* @param {string} name
*/
function Person(name){
this.name = name
}
Person.prototype = new function(){
var amount_of_limbs = 4;
/**
* Introduce yourself
*/
this.greet = function(){
alert("Hello, my name is " + this.name + " and I have " + amount_of_limbs + " limbs");
}
}
But the method greet is nowhere to be found in the resulting JSDoc documentation. What am I doing wrong?
Don't add prototype members like that. That's weird / bad / wrong.
You're setting the whole
prototypeof an existing object, rather than adding members to it. This will lead to performance problems, JS engine optimising issues and unexpected behaviour.If you somehow need to overwrite the prototype, you should use
Object.setPrototypeOf()method. Which is still not recommended even though it's a native method.If your only problem is to "hide" some private constant, you have these options:
_prefix for private vars/constants and use JSDoc@privatetag.