Hi,
I just wanted to post a nice snippet I just made...er, actually I just ripped it from the fun (function) snippet. It goes like this:
prototype.${1:method_name} = function(${2:first_argument}) { ${0:// body...} };
I have it set up to expand on proto<tab>. Actually, after thinking about it, maybe this would be better:
${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) { ${0:// body...} };
Either way, I think this is really useful because like all good snippets it keeps you from typing a bunch of stuff that is always the same, and it keeps you from forgetting the trailing semicolon (which the fun snippet and auto-close brace omit).
Any chance on getting something like this included with Textmate out of the box? Forgive me if this has already been discussed; a quick search on the list and wiki didn't turn up anything on this subject.
Also, the fun snippet that's included uses "# body..." instead of "// body...". Is this intentional, or was the hash just forgotten when porting the snippet from another language?
Mike
On 19/2/2006, at 4:31, Mike Ter Louw wrote:
[...] Any chance on getting something like this included with Textmate out of the box?
I added the second version of the prototype snippet (but with open brace on a new line, to match the function snippet -- I don’t know if there’s a de-facto brace standard for JS!?!).
Also, the fun snippet that's included uses "# body..." instead of "// body...". Is this intentional, or was the hash just forgotten when porting the snippet from another language?
The latter, I presume :) I fixed it, thanks.
Thanks, Allan!
Allan Odgaard wrote:
I added the second version of the prototype snippet (but with open brace on a new line, to match the function snippet -- I don’t know if there’s a de-facto brace standard for JS!?!).
Like other C-like languages, I think it's mainly a matter of taste and the uniformity of having them both the same is the important thing.
JavaScript is a little bit different in that the code has to be sent to the client (typical use, not counting widgets et al.) before it can be interpreted. That being the case, you'll often see people reducing variable names down to a single character in sufficiently encapsulated code. While descriptive names are usually preferred, you can usually get away with it in JS. That being said, having the brace not requiring an extra linefeed can save you a few extra bytes in a long script.
But then, there are JavaScript compactors on the net that pretty much eliminate whitespace entirely, so we come back to it just being a matter of taste or going along with convention.
Mike