《悟透JavaScript》学习札记七之对象素描
来源:互联网 发布:dota2 知乎话题 编辑:程序博客网 时间:2024/05/01 14:36
JavaScript对象表示法:JavaScript Object Notation,即JSON。
1.创建一个没有任何属性的对象: var o = {};
2.创建一个对象并设置属性及初始值:var person = {name: "Kevin", age: 24, married: false};
3.创建一个对象并设置属性和方法:var speaker = {text: "Hello world!", say: function(){alert(this.text);}};
speaker.say(); // output: Hello world!
4.创建一个更复杂的对象,嵌套其他对象和对象数组等:
var company =
{
name: "Microsoft",
product: "softwares",
chairman: {name: "Bill Gates", age: 60},
employees: [{name: "Kevin", age: 24},{name: "Ben", age: 26}],
readme: function(){document.write(this.name + " product " + this.product);}
};
company.readme(); // output: Microsoft product softwares
注: JSON 是JavaScript对象最好的序列化形式,比XML更简洁,也更省空间。当需要将JSON字符串变成一个JavaScript对象时,只需要使用eval函数这个强大的数码转换引擎,就立即能得到一个JavaScript内存对象。- 《悟透JavaScript》学习札记七之对象素描
- 悟透JavaScript之对象素描
- 悟透JavaScript-对象素描
- 悟透JavaScript - 对象素描
- 《悟透JavaScript》学习札记五之奇妙的对象
- 《悟透JavaScript》学习札记六之放下对象
- 《悟透JavaScript》学习札记八之构造对象
- 《悟透JavaScript》学习札记之标准网页
- 悟透JavaScript(李站老师)-对象素描
- 《悟透JavaScript》学习札记一之回归简单
- 《悟透JavaScript》学习札记二之没有类
- 《悟透JavaScript》学习札记三之函数的魔力
- 《悟透JavaScript》学习札记九之初看原型
- 《悟透JavaScript》学习札记十之原型扩展
- 《悟透JavaScript》学习札记十一之原型真谛一
- 《悟透JavaScript》学习札记十一之原型真谛二
- 《悟透JavaScript》学习札记之响应DOM事件
- 《悟透JavaScript》学习札记之响应DOM事件
- 我的Emacs配置(.emacs 和 load-files.el) -- 001
- hdu3861 The King’s Problem
- 对中断的一点理解
- proc/[pid]/stat 文件解释
- 不要在功能上竞争
- 《悟透JavaScript》学习札记七之对象素描
- 我的Emacs配置(misc.el) -- 002
- STRUTS学习笔记(一)
- 笔试题2
- 一个菜鸟程序员几年的工作体会与总结
- visual studio中调用其他项目的代码
- C++中extern “C”含义深层探索
- 国内互联网产品
- jqgrid网址