JavascriptÃæÏò¶ÔÏó»ù´¡ÖªÊ¶
1¡¢ÈçºÎ¶¨ÒåÒ»¸öÀ࣬ʹÓÃÈçÏÂÓï·¨À´´´½¨Ò»¸öÀà
function Person(name, age){ //Ï°¹ßÉϵÚÒ»¸ö×Öĸ´óд //thisÐÞÊεıäÁ¿³ÆΪÊôÐÔ this.name = name; this.age = age; //Èç¹ûÊôÐÔÖµÊÇÒ»¸öº¯Êý£¬ÔòÕâ¸öÊôÐÔ¾ÍÊÇÒ»¸ö·½·¨ this.play = function(){ alert('play football...'); }; }2¡¢ÈçºÎ´´½¨¸ÃÀàµÄʵÀý
var p = new Person('zs', 22); p.play(); p.name;3¡¢´´½¨javascript¶ÔÏóµÄÁíÍâÁ½ÖÖ·½Ê½
(1)ÏÈ´´½¨Ò»¸öObjectÀàÐ͵ÄʵÀý£¬È»ºóÔö¼ÓеÄÊôÐԺͷ½·¨
javascriptÊÇÒ»ÖÖ¶¯Ì¬ÓïÑÔ£¬¿ÉÒÔÔÚÔËÐÐʱΪ¶ÔÏóÔö¼ÓеÄÊôÐԺͷ½·¨
var obj = new Object(); obj.name = 'zs'; obj.age = 22; obj.play = function(){ alert('play...'); };(2)ʹÓÓjson”Óï·¨
var p = {'name':'zs','age':22}; var p = {'name':'zs','play':function(){ alert('hello'); }};»òÕß
var p = {name:'zs',age:22,marrid:false}; var p = {name:'zs',play:function(){ alert('hello'); }};ÊôÐÔÖµÈç¹ûÊÇ×Ö·û´®±ØÐëÓÃÒýºÅÀ¨ÆðÀ´(µ¥Ë«)
ÊôÐÔÖµÔÊÐínumber,string,boolean,null,Object
var p = {name:'zs', address:{ city:'beijing', street:'ca' } };Ò»¸öÍêÕûµÄÀý×Ó
<html> <head> <script> function f1(){ //var p = {'name':'zs','age':22}; //var p = {name:'zs',age:22,marrid:false}; var p = {name:'zs', address:{ city:'beijing', street:'ca' } }; //alert(p.name); alert(p.address.city); } function f2(){ var arr = [ {'name':'zs','age':22}, {'name':'ls','age':32} ]; alert(arr[1].name); } </script> </head> <body> <input type="button" value="click me" onclick="f2();"/> </body> </html>
¡¡