惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
LangChain Blog
量子位
GbyAI
GbyAI
B
Blog RSS Feed
月光博客
月光博客
人人都是产品经理
人人都是产品经理
腾讯CDC
Recent Announcements
Recent Announcements
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
The Cloudflare Blog
D
Docker
Cyberwarzone
Cyberwarzone
U
Unit 42
NISL@THU
NISL@THU
C
Check Point Blog
B
Blog
大猫的无限游戏
大猫的无限游戏
Cisco Talos Blog
Cisco Talos Blog
Recorded Future
Recorded Future
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
G
GRAHAM CLULEY
Engineering at Meta
Engineering at Meta
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 叶小钗
P
Proofpoint News Feed
F
Fortinet All Blogs
V
V2EX
T
Threat Research - Cisco Blogs
T
Threatpost
S
SegmentFault 最新的问题
Know Your Adversary
Know Your Adversary
雷峰网
雷峰网
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - 司徒正美
P
Privacy & Cybersecurity Law Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
TaoSecurity Blog
TaoSecurity Blog
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Y
Y Combinator Blog
P
Privacy International News Feed
L
Lohrmann on Cybersecurity
AWS News Blog
AWS News Blog
G
Google Developers Blog
美团技术团队

博客园 - 澜心

面向对象语言的new操作 C#在word中插入上标的问题 新建SSIS项目失败或者在SSIS项目中新建包失败 简单数据库操作 往消息队列传数据的存储过程 C#泛型学习 空气污染指数的计算公式是什么?(API) 行列转换 - 澜心 - 博客园 数据中心和数据仓库,在信息化建设中有何作用? - 澜心 - 博客园 【求助】Vs2005当前不能命中断点 自动加载用户控件问题【找到部分原因】 【讨论】程序员的发展道路如何规划,欢迎大家加入讨论 sql常用函数汇总 网站配色方案学习 用例指南 用例 UseCase 系统分析员基本功 网站安装步骤 sqlserver2000下载地址 SQLServer2000安装图解
javascript复习一 JavaScript的面向对象
澜心 · 2011-09-13 · via 博客园 - 澜心

2011-09-13 21:42  澜心  阅读(557)  评论()    收藏  举报

以前自己仅是根据自己的编程经验来处理javascript,javascript的入门门槛儿较低,不用知道很多的细节就可以编码,以至于自己并没有系统的学习。最近想系统的学习一下,特记录如下。

  1. JavaScript 对象是字典

在javascript中对象是一组键值对,我们可以通过  "."或者 "[]" 来获取或者设置对象的属性。

var person = new Object();
person.name = "jerry";
person.age  = 28;

alert("名称:" + person.name + "  年龄" + person.age);

以上代码等效于下面的代码:

var person1 = {"name":"jerry","age":28};
alert("名称:" + person1.name + "  年龄" + person1.age);

这就是我们熟悉的JSON表示方法。

    2:给对象加入方法。

var person = new Object();
person.name = "jerry";
person.age  = 28;

person.sayHello = function(msg)
{alert(msg)};
//alert("名称:" + person.name + "  年龄" + person.age);

var person1 = {"name":"jerry","age":28
,"sayHello":function(msg)
{alert(msg);}
};
person1.sayHello("hello word");

person.sayHello("hello word");

3:用functions来封装对象

function person(name)
{
	this.name = name;
	this.sayHello = function()
	{alert(this.name);};
}
var p = new person("jeffry");
p.sayHello();