JavaScript保留關鍵字及危險變數名 定義變數名需謹慎
在開發過程當中,如果沒有必要就儘可能少的使用以下列出的單詞作為變數名稱或者屬性名稱,關鍵字是嚴格不允許,而瀏覽器定義的變數名或者類名在使用的時候注意確保範圍
一、現在 EMCAScript 中的關鍵字:
break |
case |
catch |
continue |
default |
delete |
do |
else |
finally |
for |
function |
if |
in |
instanceof |
new |
return |
switch |
this |
throw |
try |
typeof |
var |
void |
while |
with |
|
|
|
二、將來EMCAScript 5中可能使用的關鍵字:
abstract |
boolean |
byte |
char |
class |
debugger |
double |
enum |
extends |
final |
float |
goto |
implements |
int |
interface |
long |
native |
package |
private |
protected |
public |
short |
static |
super |
synchronized |
throws |
transient |
volatile |
三、 JavaScript2.0(future) 不明確提到的關鍵字:
as |
const |
export |
import |
is |
use |
|
|
四、絕大部分瀏覽器中預定義的一些變數名和類名:
Anchor |
anchors |
Applet |
applets |
Area |
Array |
Body |
Button |
Checkbox |
Date |
document |
Error |
EvalError |
FileUpload |
Form |
forms |
frame |
frames |
Function |
Hidden |
History |
history |
Image |
images |
Link |
links |
location |
Math |
MimeType |
mimetypes |
navigator |
Number |
Object |
Option |
options |
Password |
Plugin |
plugins |
Radio |
RangeError |
ReferenceError |
RegExp |
Reset |
screen |
Script |
Select |
String |
Style |
StyleSheet |
Submit |
SyntaxError |
Text |
Textarea |
TypeError |
URIError |
window |
五、全域屬性及方法:
Infinity |
NaN |
undefined |
decodeURI |
decodeURIComponent |
encodeURI |
encodeURIComponent |
escape |
eval |
isFinite |
isNaN |
parseFloat |
parseInt |
unescape |
|
|
六、Window對象的屬性和方法:
1、property:
closed |
Components |
content |
controllers |
defaultStatus |
directories |
document |
frames |
history |
innerHeight |
innerWidth |
length |
location |
locationbar |
menubar |
name |
navigator |
opener |
outerHeight |
outerWidth |
pageXOffset |
pageYOffset |
parent |
personalbar |
pkcs11 |
prompter |
screen |
screenX |
screenY |
scrollbars |
scrollX |
scrollY |
self |
statusbar |
toolbar |
top |
window |
|
|
|
2、Methods:
alert |
back |
blur |
captureevents |
clearInterval |
clearTimeout |
close |
confirm |
dump |
escape |
focus |
forward |
getAttention |
getSelection |
home |
moveBy |
moveTo |
open |
print |
prompt |
releaseevents |
resizeBy |
resizeTo |
scroll |
scrollBy |
scrollByLines |
scrollByPages |
scrollTo |
setCursor |
setInterval |
setTimeout |
sizeToContents |
stop |
unescape |
updateCommands |
|
七、事件:
onabort |
onblur |
onchange |
onclick |
onclose |
ondragdrop |
onerror |
onfocus |
onkeydown |
onkeypress |
onkeyup |
onload |
onmousedown |
onmousemove |
onmouseout |
onmouseover |
onmouseup |
onpaint |
onreset |
onresize |
onscroll |
onselect |
onsubmit |
onunload |
八、特定瀏覽器中預定義的變數名和類名:
all |
assign |
clientInformation |
element |
embed |
embeds |
event |
frameRate |
getClass |
java |
JavaArray |
JavaClass |
JavaObject |
JavaPackage |
layer |
layers |
netscape |
offscreenBuffering |
opener |
packages |
secure |
status |
sun |
taint |
toSource |
toString |
untaint |
valueOf |
原文地址:http://www.qianduanzu.com/2012033020.html