ECMAScript——命名規範

一、js中是嚴格區分大小寫的
test和Test是兩個名字

二、使用駝峯命名法
第一個首字母小寫,其他每個有意義的單詞的首字母都要大寫
能夠使用字母、數字、下劃線、$命名,可是數字不能做爲開頭,如:
學生信息: studentInfo studentInfo2
人員的重要信息: personImportInfo
$person:一般項目中這種名字表明的是jQuery專用的名字

三、不能使用關鍵字和保留字
關鍵字:js中具備特殊意義的詞,咱們不能隨便拿來命名
保留字:將來可能會成爲關鍵字的

關鍵字:javascript

breakjava

casethis

catchspa

continuedebug

defaultip

deleteget

doit

elseio

finallytable

for

function

if

in

instanceof

new

return

switch

this

throw

try

typeof

var

void

while

with

保留字:

abstract

boolean

byte

char

class

const

debugger

double

enum

export

extends

final

float

goto

implements

import

int

interface

long

native

package

private

protected

public

short

static

super

synchronized

throws

transient

volatile

 

 

 

 

 

 四、對於全局變量或者公用的變量咱們最好起名字的時候前面加上 _ ,例如:_this、_num這些都表明是公用的變量

相關文章
相關標籤/搜索