javascript鍩虹鐭ヨ瘑 瀵硅薄
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript鍩虹鐭ヨ瘑 瀵硅薄相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e6%b5%8f%e8%a7%88%e5%99%a8' title='娴忚鍣?>娴忚鍣?/a> null false name 鍙橀噺 ... 鏈嬪弸 class
瀵硅薄
JavaScript鐨勫璞℃槸涓€绉嶆棤搴忕殑闆嗗悎鏁版嵁绫诲瀷锛屽畠鐢辫嫢骞查敭鍊煎缁勬垚銆?/p>
JavaScript鐨勫璞$敤浜庢弿杩扮幇瀹炰笘鐣屼腑鐨勬煇涓璞°€備緥濡傦紝涓轰簡鎻忚堪鈥滃皬鏄庘€濊繖涓窐姘旂殑灏忔湅鍙嬶紝鎴戜滑鍙互鐢ㄨ嫢骞查敭鍊煎鏉ユ弿杩颁粬锛?/p>
var xiaoming = {
name: 鈥樺皬鏄庘€?span style="color: #000000">,
birth: 1990,
school: 鈥楴o.1 Middle School鈥?span style="color: #000000">,
height: 1.70,
weight: 65,
score: null
};
JavaScript鐢ㄤ竴涓?code>{...}
琛ㄧず涓€涓璞★紝閿€煎浠?code>xxx: xxx
褰㈠紡鐢虫槑锛岀敤,
闅斿紑銆?span style="color: #ff0000">娉ㄦ剰锛屾渶鍚庝竴涓敭鍊煎涓嶉渶瑕佸湪鏈熬鍔?code>,
锛?/span>濡傛灉鍔犱簡锛屾湁鐨勬祻瑙堝櫒锛堝浣庣増鏈殑IE锛夊皢鎶ラ敊銆?/p>
涓婅堪瀵硅薄鐢虫槑浜嗕竴涓?code>name
灞炴€э紝鍊兼槸鈥樺皬鏄庘€?/code>锛?code>birth
灞炴€э紝鍊兼槸1990
锛屼互鍙婂叾浠栦竴浜涘睘鎬с€傛渶鍚庯紝鎶婅繖涓璞¤祴鍊肩粰鍙橀噺xiaoming
鍚庯紝灏卞彲浠ラ€氳繃鍙橀噺xiaoming
鏉ヨ幏鍙栧皬鏄庣殑灞炴€т簡锛?/p>
xiaoming.name; // 鈥樺皬鏄庘€?/span>
xiaoming.birth; // 1990
璁块棶灞炴€ф槸閫氳繃.
鎿嶄綔绗﹀畬鎴愮殑锛屼絾杩欒姹傚睘鎬у悕蹇呴』鏄竴涓湁鏁堢殑鍙橀噺鍚嶃€?span style="color: #ff0000">濡傛灉灞炴€у悕鍖呭惈鐗规畩瀛楃锛屽氨蹇呴』鐢?code>鈥樷€?/code>鎷捣鏉?/span>锛?/p>
var xiaohong = {
name: 鈥樺皬绾⑩€?span style="color: #000000">,
鈥榤iddle-school鈥? 鈥楴o.1 Middle School鈥?span style="color: #000000">
};
xiaohong
鐨勫睘鎬у悕middle-school
涓嶆槸涓€涓湁鏁堢殑鍙橀噺锛屽氨闇€瑕佺敤鈥樷€?/code>鎷捣鏉ャ€傝闂繖涓睘鎬т篃鏃犳硶浣跨敤.
鎿嶄綔绗︼紝蹇呴』鐢?code>[鈥榵xx鈥榏
鏉ヨ闂細
xiaohong[鈥榤iddle-school鈥榏; // 鈥楴o.1 Middle School鈥?/span>
xiaohong[鈥榥ame鈥榏; // 鈥樺皬绾⑩€?/span>
xiaohong.name; // 鈥樺皬绾⑩€?/span>
涔熷彲浠ョ敤xiaohong[鈥榥ame鈥榏
鏉ヨ闂?code>xiaohong
鐨?code>name
灞炴€э紝涓嶈繃xiaohong.name
鐨勫啓娉曟洿绠€娲併€?/p>
鎴戜滑鍦ㄧ紪鍐橨avaScript浠g爜鐨勬椂鍊欙紝灞炴€у悕灏介噺浣跨敤鏍囧噯鐨勫彉閲忓悕锛岃繖鏍峰氨鍙互鐩存帴閫氳繃object.prop
鐨勫舰寮忚闂竴涓睘鎬т簡銆?/p>
瀹為檯涓奐avaScript瀵硅薄鐨勬墍鏈夊睘鎬ч兘鏄瓧绗︿覆锛屼笉杩囧睘鎬у搴旂殑鍊煎彲浠ユ槸浠绘剰鏁版嵁绫诲瀷銆?/span>
濡傛灉璁块棶涓€涓笉瀛樺湪鐨勫睘鎬т細杩斿洖浠€涔堝憿锛烰avaScript瑙勫畾锛岃闂笉瀛樺湪鐨勫睘鎬т笉鎶ラ敊锛岃€屾槸杩斿洖undefined
var xiaoming = {
name: 鈥樺皬鏄庘€?span style="color: #000000">
};
xiaoming.age; // undefined
鐢变簬javascript鐨勫璞℃槸鍔ㄦ€佺被鍨嬶紝浣犲彲浠ヨ嚜鐢卞湴缁欎竴涓璞℃坊鍔犳垨鍒犻櫎灞炴€э細
var xiaoming = {
name: 鈥樺皬鏄庘€?span style="color: #000000">
};
xiaoming.age; // undefined
xiaoming.age = 18; // 鏂板涓€涓猘ge灞炴€?/span>
xiaoming.age; // 18
delete xiaoming.age; // 鍒犻櫎age灞炴€?/span>
xiaoming.age; // undefined
delete xiaoming[鈥榥ame鈥榏; // 鍒犻櫎name灞炴€?/span>
xiaoming.name; // undefined
delete xiaoming.school; // 鍒犻櫎涓€涓笉瀛樺湪鐨剆chool灞炴€т篃涓嶄細鎶ラ敊
濡傛灉鎴戜滑瑕佹娴?code>xiaoming
鏄惁鎷ユ湁鏌愪竴灞炴€э紝鍙互鐢?code>in
鎿嶄綔绗︼細
var xiaoming = {
name: 鈥樺皬鏄庘€?span style="color: #000000">,
birth: 1990,
school: 鈥楴o.1 Middle School鈥?span style="color: #000000">,
height: 1.70,
weight: 65,
score: null
};
鈥榥ame鈥?in xiaoming; // true
鈥榞rade鈥?in xiaoming; // false
涓嶈繃瑕佸皬蹇冿紝濡傛灉in
鍒ゆ柇涓€涓睘鎬у瓨鍦紝杩欎釜灞炴€т笉涓€瀹氭槸xiaoming
鐨勶紝瀹冨彲鑳芥槸xiaoming
缁ф壙寰楀埌鐨勶細
鈥榯oString鈥?in xiaoming; // true
鍥犱负toString
瀹氫箟鍦?code>object
瀵硅薄涓紝鑰屾墍鏈夊璞℃渶缁堥兘浼氬湪鍘熷瀷閾句笂鎸囧悜object
锛屾墍浠?code>xiaoming
涔熸嫢鏈?code>toString
灞炴€с€?/p>
瑕佸垽鏂竴涓睘鎬ф槸鍚︽槸xiaoming
鑷韩鎷ユ湁鐨勶紝鑰屼笉鏄户鎵垮緱鍒扮殑锛屽彲浠ョ敤hasOwnProperty()
鏂规硶锛?/p>
var xiaoming = { name: 鈥樺皬鏄庘€?span style="color: #000000"> }; xiaoming.hasOwnProperty(鈥榥ame鈥?; // true xiaoming.hasOwnProperty(鈥榯oString鈥?; // false
以上是关于javascript鍩虹鐭ヨ瘑 瀵硅薄的主要内容,如果未能解决你的问题,请参考以下文章
Linux绯荤粺鍩虹鐭ヨ瘑鐩綍銆佸厓鏁版嵁銆佽蒋纭摼鎺ャ€佹枃浠剁鐞嗗懡浠ゃ€乿im鏌ユ壘鏇挎崲銆乿imtab缂╄繘