首页 > PHP > 悟透JavaScript

悟透JavaScript

2009年06月30号
查看评论 发表评论 2,679次浏览

对象素描

    已经说了许多了许多话题了,但有一个很基本的问题我们忘了讨论,那就是:怎样建立对象?

    在前面的示例中,我们已经涉及到了对象的建立了。我们使用了一种被称为JavaScript Object Notation(缩写JSON)的形式,翻译为中文就是“JavaScript对象表示法”。

    JSON为创建对象提供了非常简单的方法。例如,
    创建一个没有任何属性的对象:

var o = {};

    创建一个对象并设置属性及初始值:

var person = {name: Angel, age: 18, married: false};

    创建一个对象并设置属性和方法:

var speaker = {text: Hello World, say: function(){alert(this.text)}};

     创建一个更复杂的对象,嵌套其他对象和对象数组等:

    var company =
    {
        name: 
Microsoft,
        product: 
softwares,
        chairman: {name: 
Bill Gates, age: 53, Married: true},
        employees: [{name: 
"Angel", age: 26, Married: false}, {name: "Hanson", age: 32, Marred: true}],
        readme: 
function() {document.write(this.name +  product  + this.product);}
    };

    JSON的形式就是用大括“{}”号包括起来的项目列表,每一个项目间并用逗号“,”分隔,而项目就是用冒号“:”分隔的属性名和属性值。这是典型的字典表示形式,也再次表明了 JavaScript里的对象就是字典结构。不管多么复杂的对象,都可以被一句JSON代码来创建并赋值。

    其实,JSON就是JavaScript对象最好的序列化形式,它比XML更简洁也更省空间。对象可以作为一个JSON形式的字符串,在网络间自由传递和交换信息。而当需要将这个JSON字符串变成一个JavaScript对象时,只需要使用eval函数这个强大的数码转换引擎,就立即能得到一个JavaScript内存对象。正是由于JSON的这种简单朴素的天生丽质,才使得她在AJAX舞台上成为璀璨夺目的明星。

    JavaScript就是这样,把面向对象那些看似复杂的东西,用及其简洁的形式表达出来。卸下对象浮华的浓妆,还对象一个眉目清晰!

页面: 1 2 3 4 5 6 7 8 9 10

类别PHP 标签
  1. cheap Bikinis
    发表于 2010年06月15号 05时13分37秒 | 1楼

    I agree with most of this article

  2. Hermes Handbags
    发表于 2010年06月20号 06时41分45秒 | 2楼

    The FUN comes the FIRST… :D

  3. kobe shoes
    发表于 2010年06月25号 05时50分09秒 | 3楼

    Thank you for every word that you wrote..every one of them touches my heart…

  4. ghd hair straighteners
    发表于 2010年06月28号 05时57分32秒 | 4楼

    Wow, this blog really caught my eye!

  5. nike airforce
    发表于 2010年06月28号 08时41分24秒 | 5楼

    Good point on the concience

  6. herve leger dress
    发表于 2010年06月29号 00时17分34秒 | 6楼

    I am especially impressed with your post.

  7. mbt shoes clearance
    发表于 2010年07月08号 04时04分09秒 | 7楼

    I complitely agree with you..Thank you for bringing it up!

  8. lacoste t-shirts
    发表于 2010年07月09号 14时28分51秒 | 8楼

    wow powerful!

  9. bmw watch
    发表于 2010年07月09号 17时39分41秒 | 9楼

    Ooh!! I must remember this one!!

  10. lacoste polo shirts
    发表于 2010年07月09号 17时43分41秒 | 10楼

    That’s a good question.

  11. puma sneakers
    发表于 2010年07月09号 17时52分31秒 | 11楼

    I was thinking today that being grateful every moment is great freedom.

  12. Gucci Designer Handbags
    发表于 2010年07月19号 19时24分11秒 | 12楼

    Great, Good Luck!

  13. LeBron James Shoes
    发表于 2010年07月20号 10时39分03秒 | 13楼

    they are … powerful

  14. MBT Shoes Clearance
    发表于 2010年07月21号 11时53分13秒 | 14楼

    thank you for agreeing to share a precious moment of your life.

  15. air jordan 2009
    发表于 2010年07月22号 13时51分18秒 | 15楼

    It is fascinating to me how this article about.

评论页数:
1 2 258
你必需 登陆 才能发表评论.