views:

200

answers:

2

This question is similar to http://stackoverflow.com/questions/736120/why-are-methods-in-ruby-documentation-preceded-by-a-pound-sign

I understand why in Ruby instance methods are proceeded with a pound sign, helping to differentiate talking about SomeClass#someMethod from SomeObject.someMethod and allowing rdoc to work. And I understand that the authors of PrototypeJS admire Ruby (with good reason) and so they use the hash mark convention in their documentation.

My question is: is this a standard practice amongst JavaScript developers or is it just Prototype developers who do this?

Asked another way, is it proper for me to refer to instance methods in comments/documentation as SomeClass#someMethod? Or should my documentation refer to `SomeClass.someMethod?

+1  A: 

I think it comes from javadoc.

http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/javadoc.html#{@link}

Pablo Cabrera
If you can provide a link for that, I'll accept your answer
Josh
Certainly the first place I saw it. It's by analogy to the URL page#fragment syntax for links.
bobince
There you go =]
Pablo Cabrera
Ah. It's specifically stating: package.class#member is any valid program element name that is referenced -- a package, class, interface, constructor, method or field name -- except that the character ahead of the member name should be a hash character (#).
Josh
+3  A: 

No, I have not yet met another JavaScript project that uses this notation.

Something like this is useful in JavaScript, though, because unlike in many languages Class.methodName would refer to classmethods like String.fromCharCode, not instance methods which is what you are more often talking about. The method invoked by myinstance.methodName would be not MyClass.methodName but MyClass.prototype.methodName, and MyClass.prototype is an annoyance to keep typing.

(The standard JS library confuses this by making many instance methods also have a corresponding classmethod. But they're different functions.)

is it proepr for me to refer to instance methods in comments/documentation as SomeClass#someMethod?

Do what you like/find most readable. There's no standard here.

bobince
Good answer. So if you were reading my documentation and I consistently used # to designate instance methods, you think it would be clear to you?
Josh
It would be clear to me from other languages. I wouldn't expect JS authors to know it, but hopefully it's grokkable from context!
bobince