📄 4.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>基于对象的JavaScript语言</title>
<meta name="Microsoft Theme" content="maize 011">
</head>
<body background="maizbk.jpg" bgcolor="#FFFFFF" text="#000000" link="#669999" vlink="#999900" alink="#3366CC">
<!--mstheme--><font face="宋体"><!--mstheme--></font>
<table border="0" width="100%">
<tr>
<td width="100%">
<!--mstheme--><font face="宋体">
<p align="center" style="text-align: center; line-height: 150%"><b><font size="4" color="#000000"><span style="font-family: 宋体; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman">基于对象的</span><span lang="EN-US">JavaScript</span><span style="font-family: 宋体; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman">语言</span></font></b><span lang="EN-US" style="FONT-SIZE: 24pt"><o:p>
</o:p>
</span></p>
<p style="line-height: 150%"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"> <font size="3"> </font></span><font size="3"><span lang="EN-US">JavaScript</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语言是基于对象的(</span><span lang="EN-US">Object-Based</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">),而不是面向对象的(</span><span lang="EN-US">object-oriented</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">)。之所以说它是一门基于对象的语言,主要是因为它没有提供象抽象、继承、重载等有关面向对象语言的许多功能。而是把其它语言所创建的复杂对象统一起来,从而形成一个非常强大的对象系统。</span></font></p>
<p style="line-height: 150%"><font size="3"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"> 虽然</span><span lang="EN-US">JavaScript</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语言是一门基于对象的,但它还是具有一些面向对象的基本特征。它可以根据需要创建自己的对象,从而进一步扩大</span><span lang="EN-US">JavaScript</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">的应用范围,增强编写功能强大的</span><span lang="EN-US">Web</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">文档。</span></font></p>
<p style="line-height: 150%"><b><font size="3"><span style="FONT-FAMILY: 宋体; FONT-SIZE: 18pt; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">一、</span><span style="font-family: 宋体; mso-ascii-font-family: Times New Roman; mso-hansi-font-family: Times New Roman">对象的基础知识</span><span lang="EN-US" style="FONT-SIZE: 18pt"><o:p>
</o:p>
</span></font></b></p>
<p style="line-height: 150%"><b><font size="3"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">1、对象的基本结构</span><span lang="EN-US"><o:p>
</o:p>
</span></font></b></p>
<p style="line-height: 150%"><font size="3"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"> </span><span lang="EN-US">JavaScript</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中的对象是由属性</span><span lang="EN-US">(properties)</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">和方法</span><span lang="EN-US">(methods)</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">两个基本的元素的构成的。前者是对象在实施其所需要行为的过程中,实现信息的装载单位,从而与变量相关联;后者是指对象能够按照设计者的意图而被执行,从而与特定的函数相联。</span></font></p>
<p style="line-height: 150%"><b><font size="3"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">2、引用对象的途径</span><span lang="EN-US"><o:p>
</o:p>
</span></font></b></p>
<p style="line-height: 150%"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3"> 一个对象要真正地被使用,可采用以下几种方式获得:</font></span></p>
<p style="text-indent: -18pt; tab-stops: list 72.0pt; mso-list: l9 level2 lfo1; line-height: 150%; margin-left: 72pt"><span lang="EN-US" style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><font size="3">o<span style="FONT: 7pt 'Times New Roman'">
</span></font></span><font size="3"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">引用</span><span lang="EN-US">JavaScript</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">内部对象;</span></font></p>
<p style="text-indent: -18pt; tab-stops: list 72.0pt; mso-list: l9 level2 lfo1; line-height: 150%; margin-left: 72pt"><span lang="EN-US" style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><font size="3">o<span style="FONT: 7pt 'Times New Roman'">
</span></font></span><font size="3"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">由浏览器环境中提供;</span></font></p>
<p style="text-indent: -18pt; tab-stops: list 72.0pt; mso-list: l9 level2 lfo1; line-height: 150%; margin-left: 72pt"><span lang="EN-US" style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><font size="3">o<span style="FONT: 7pt 'Times New Roman'">
</span></font></span><font size="3"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">创建新对象。</span></font></p>
<p style="line-height: 150%"><font size="3"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"> 这就是说一个对象在被引用之前,这个对象必须存在,否则引用将毫无意义,而出现错误信息。从上面中我们可以看出</span><span lang="EN-US">JavaScript</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">引用对象可通过三种方式获取。要么创建新的对象,要么利用现存的对象。</span></font></p>
<p style="line-height: 150%"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">3、<b>有关对象操作语句</b></font></span></p>
<p style="line-height: 150%"><font size="3"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"> </span><span lang="EN-US">JavaScript</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">不是一纯面向对象的语言,它设有提供面向对象语言的许多功能,因此</span><span lang="EN-US">JavaScript</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">设计者之所以把它你</span><span lang="EN-US">“</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">基于对象</span><span lang="EN-US">”</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">而不是面向对象的语言,在</span><span lang="EN-US">JavaScript</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">中提供了几个用于操作对象的语句和关键字及运算符。</span></font></p>
<p style="line-height: 150%; margin-left: 36pt"><span lang="EN-US"><font size="3">1</font></span><font size="3"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">)、</span><span lang="EN-US">For...in</span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">语句</span></font></p>
<p style="line-height: 150%; margin-left: 72pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">格式如下:</font></span></p>
<p style="line-height: 150%; margin-left: 72pt"><span lang="EN-US"><font size="3">For</font></span><font size="3"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">(对象属性名</span><span lang="EN-US">
in </span><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">已知对象名)</span></font></p>
<p style="line-height: 150%; margin-left: 72pt"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'"><font size="3">说明:</font></span></p>
<p style="text-indent: -18pt; tab-stops: list 72.0pt; mso-list: l7 level2 lfo2; line-height: 150%; margin-left: 72pt"><span lang="EN-US" style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-size: 12.0pt; mso-bidi-font-family: 'Times New Roman'"><font size="3">o<span style="FONT: 7pt 'Times New Roman'">
</span></font></span><font size="3"><span style="FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">该语句的功能是用于对已知对象的所有属性进行操作的控制循环。它是将一个已知对象的所有属性反复置给一个变量;而不是使用计数器来实现的。</span></font></p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -