Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Function, variable et al names

Reply
Thread Tools

Function, variable et al names

 
 
Andrew Poulos
Guest
Posts: n/a
 
      12-29-2004
If I'm writing a sizeable chunk of javascript (1000s of lines) and it
includes lots of custom functions, global variables, prototypes etc is
there an agreed, customary, conventional, or best practise way to name
them? What I'm worried about is inadvertently having a naming clash
where, say, a function and a global variable end up being named the same.

I have a friend who starts the name of every function with "f" eg.
fMyFunction, and every global variable with "g" eg. gMyVariable. I'm not
sure if this is the "smartest" way to do it.

Should I make a separate index with each name listed with a description
of it's purpose, usage etc?


Andrew Poulos
 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      12-29-2004
Andrew Poulos wrote on 29 dec 2004 in comp.lang.javascript:
> If I'm writing a sizeable chunk of javascript (1000s of lines) and it
> includes lots of custom functions, global variables, prototypes etc is
> there an agreed, customary, conventional, or best practise way to name
> them? What I'm worried about is inadvertently having a naming clash
> where, say, a function and a global variable end up being named the same.


Write modular code that has its own defined local variables, and keep the
global variables to a minimum.

Enter the modules [=functions] with all variables as parameters and exit
the code with all parameters in the return value. The latter is not that
easy if there are more than one return values, but could be done with an
array.

That way the modules can even be reentrant.

The hopefully very few global variables could be given special names,
but that is not necessary,
as there is no strict objection to duplicate variable names:

<script type='text/javascript'>
var v = 7; //global

function f(){
var v = 8; //local

alert('local v = ' + v)
alert('global v = ' + window['v'])
}
f()
</script>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic variable names or using a variable as another's name Peter Buckley Ruby 5 02-27-2009 06:05 PM
checking for mis-spelled variable names / function names News123 Python 2 11-26-2008 12:37 AM
confusion between global names and instantiated object variable names wanwan Python 3 10-14-2005 09:46 PM
Converting 'flat' gate level names to hierarchical names Paddy McCarthy VHDL 3 09-24-2004 05:34 PM
table field names vs. display names Bob ASP .Net 1 07-30-2004 05:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57