Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referring to javascript instance methods with a pound/hash sign

This question is similar to Why are methods in Ruby documentation preceded by a hash 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`?

like image 660
Josh Avatar asked Apr 06 '10 20:04

Josh


People also ask

What does a pound sign mean in Javascript?

There are several ways to use a hash mark or pound sign ( # ) in a click-through URL. But first, some background. In a URL, a hash mark, number sign, or pound sign ( # ) points a browser to a specific spot in a page or website. It is used to separate the URI of an object from a fragment identifier.

What is hash sign in Javascript?

The # means "ID". It's searching the DOM for the element with the ID `searchTerm.

What is pound sign in Ruby?

The "#{}" syntax is called 'interpolation' and the pound was picked most likely because interpolation is similar in a sense to commenting, because you are changing the context of your code (in this case to another context for execution)


1 Answers

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.

like image 79
bobince Avatar answered Oct 16 '22 20:10

bobince