PHP4 | Flash | ASP | CSS | VBScript | ADO | MySQL | JavaScript | Spring | Hibernate | win32api | 正则表达式 | 注册表 | xmlhttp .
当前位置:首页 → javascript上一篇 控制程序的流程    下一篇 创建自己的对象
在当前chm中查找:
目录
·什么是 JScript?
·使用消息框
·固有对象
·脚本问题解答
·控制程序的流程
·创建高级对象
·创建自己的对象
·的数据类型
·JScript 的变量
·FileSystemObject 词汇
·JScript 的函数
·JScript 词汇表
· 按字母顺序排列的关键字列表
·运算符操作
·concat 方法 (数组)
·concat 方法 (Array)
·concat 方法 (Array)
·join 方法
·join 方法
·join 方法
·length 属性 (Array)
·length 属性 (Array)
·length 属性 (Array)
·reverse 方法
·reverse 方法
·reverse 方法
·slice 方法 (Array)
·slice 方法
·slice 方法
·sort 方法
·sort 方法
·sort 方法
·Drives 集合
·Drives 集合
·Drives 集合
·Drives 集合
·Files 集合
·Files 集合
·Files 集合
·Files 集合
·Folders 集合
·Folders 集合
·Folders 集合
·Folders 集合
·条件编译
·条件编译
·条件编译变量
·条件编译变量
·getDate 方法
·getDate 方法
·getDate 方法
·getDay 方法
·getDay 方法
·getDay 方法
·getFullYear 方法
·getFullYear 方法
·getFullYear 方法
·getHours 方法
·getHours 方法
·getHours 方法
·getMilliseconds 方法
·getMilliseconds 方法
·getMilliseconds 方法
·getMinutes 方法
·getMinutes 方法
·getMinutes 方法
·getMonth 方法
·getMonth 方法
·getMonth 方法
·getSeconds 方法
·getSeconds 方法
·getSeconds 方法
·getTime 方法
·getTime 方法
·getTime 方法
·getTimezoneOffset 方法
·getTimezoneOffset 方法
·getTimezoneOffset 方法
·getUTCDate 方法
·getUTCDate 方法
·getUTCDate 方法
·getUTCDay 方法
·getUTCDay 方法
·getUTCDay 方法
·getUTCFullYear 方法
·getUTCFullYear 方法
·getUTCFullYear 方法
·getUTCHours 方法
·getUTCHours 方法
·getUTCHours 方法
·getUTCMilliseconds 方法
·getUTCMilliseconds 方法
·getUTCMilliseconds 方法
·getUTCMinutes 方法
·getUTCMinutes 方法
·getUTCMinutes 方法
·getUTCMonth 方法
·getUTCMonth 方法
·getUTCMonth 方法
·getUTCSeconds 方法
·getUTCSeconds 方法
·getUTCSeconds 方法
·getVarDate 方法
·getVarDate 方法
·getVarDate 方法
·getYear 方法
·getYear 方法
·getYear 方法
·parse 方法
·parse 方法
·parse 方法
·setDate 方法
·setDate 方法
·setDate 方法
·setFullYear 方法
·setFullYear 方法
·setFullYear 方法
·setHours 方法
·setHours 方法
·setHours 方法
·setMilliseconds 方法
·getMilliseconds 方法
·setMilliseconds 方法
·setMinutes 方法
·setMinutes 方法
· setMinutes 方法
·setMonth 方法
·setMonth 方法
·setMonth 方法
·setSeconds 方法
·setSeconds 方法
·setSeconds 方法
·setTime 方法
·setTime 方法
·setTime 方法
·setUTCDate 方法
·setUTCDate 方法
·setUTCDate 方法
·setUTCFullYear 方法
·setUTCFullYear 方法
·setUTCFullYear 方法
·setUTCHours 方法
·setUTCHours 方法
·setUTCHours 方法
·setUTCMilliseconds 方法
·setUTCMilliseconds 方法
·setUTCMilliseconds 方法
·setUTCMinutes 方法
·setUTCMinutes 方法
·setUTCMinutes 方法
·setUTCMonth 方法
·setUTCMonth 方法
·setUTCMonth 方法
·setUTCSeconds 方法
·setUTCSeconds 方法
·setUTCSeconds 方法
·setYear 方法
·setYear 方法
·setYear 方法
·toGMTString 方法
·toGMTString 方法
·toGMTString 方法
·toLocaleString 方法
·toLocaleString 方法
·toLocaleString 方法
·toUTCString 方法
·toUTCString 方法
·toUTCString 方法
·UTC 方法
·UTC 方法
·UTC 方法
·Add 方法 (Dictionary)
·Add 方法 (Dictionary)
·CompareMode 属性
·CompareMode 属性
·CompareMode 属性
·Count 属性
·Count 属性
·Count 属性
·Exists 方法
·Exists 方法
·Exists 方法
·Item 属性
·Item 属性
·Item 属性
·Items 方法
·Items 方法
·Items 方法
·Key 属性
·Key 属性
·Key 属性
·Keys 方法
·Keys 方法
·Keys 方法
·Remove 方法
·Remove 方法
·RemoveAll 方法
·RemoveAll 方法
·RemoveAll 方法
·Remove 方法
·AvailableSpace 属性
·AvailableSpace 属性
·AvailableSpace 属性
·DriveLetter 属性
·DriveLetter 属性
·DriveLetter 属性
·DriveType 属性
·DriveType 属性
·DriveType 属性
·FileSystem 属性
·FileSystem 属性
·FileSystem 属性
·FreeSpace 属性
·FreeSpace 属性
·FreeSpace 属性
·IsReady 属性
·IsReady 属性
·IsReady 属性
·Path 属性
·Path 属性
·Path 属性
·RootFolder 属性
·RootFolder 属性
·RootFolder 属性
·SerialNumber 属性
·SerialNumber 属性
·SerialNumber 属性
·ShareName 属性
·ShareName 属性
·ShareName 属性
·TotalSize 属性
·TotalSize 属性
·TotalSize 属性
·VolumeName 属性
·VolumeName 属性
·VolumeName 属性
·atEnd 方法
·atEnd 方法
·atEnd 方法
·item 方法
·item 方法
·item 方法
·moveFirst 方法
·moveFirst 方法
·moveFirst 方法
·moveNext 方法
·moveNext 方法
·moveNext 方法
· JScript 错误
· 特性信息
·Attributes 属性
·Attributes 属性
·Attributes 属性
·Copy 方法
·Copy 方法
·Copy 方法
·CreateTextFile 方法
·CreateTextFile 方法
·CreateTextFile 方法
·DateCreated 属性
·DateCreated 属性
·DateCreated 属性
·DateLastAccessed 属性
·DateLastAccessed 属性
·DateLastAccessed 属性
·DateLastModified 属性
·DateLastModified 属性
·DateLastModified 属性
·Delete 方法
·Delete 方法
·Delete 方法
·Drive 属性
·Drive 属性
·Drive 属性
·Move 方法
·Move 方法
·Move 方法
·Name 属性
· Name 属性
·Name 属性
·OpenAsTextStream 方法
·OpenAsTextStream 方法
·OpenAsTextStream 方法
·OpenTextFile 方法
·OpenTextFile 方法
·OpenTextFile 方法
·ParentFolder 属性
·ParentFolder 属性
·ParentFolder 属性
·ShortName 属性
·ShortName 属性
·ShortName 属性
·ShortPath 属性
·ShortPath 属性
·ShortPath 属性
·Size 属性
·Size 属性
·Size 属性
·BuildPath 方法
·BuildPath 方法
·BuildPath 方法
·CopyFile 方法
·CopyFile 方法
·CopyFile 方法
·CopyFolder 方法
·CopyFolder 方法
·CopyFolder 方法
·CreateFolder 方法
·CreateFolder 方法
·CreateFolder 方法
·DeleteFile 方法
·DeleteFile 方法
·DeleteFile 方法
·DeleteFolder 方法
·DeleteFolder 方法
·DeleteFolder 方法
·DriveExists 方法
·DriveExists 方法
·DriveExists 方法
·Drives 属性
·Drives 属性
·Drives 属性
·FileExists 方法
·FileExists 方法
·FileExists 方法
·FolderExists 方法
·FolderExists 方法
·FolderExists 方法
·GetAbsolutePathName 方法
·GetAbsolutePathName 方法
·GetAbsolutePathName 方法
·GetBaseName 方法
·GetBaseName 方法
·GetBaseName 方法
·GetDrive 方法
·GetDrive 方法
·GetDrive 方法
·GetDriveName 方法
·GetDriveName 方法
·GetDriveName 方法
·GetExtensionName 方法
·GetExtensionName 方法
·GetExtensionName 方法
·GetFile 方法
·GetFile 方法
·GetFile 方法
·GetFileName 方法
·GetFileName 方法
·GetFileName 方法
·GetFileVersion 方法
·GetFileVersion 方法
·GetFileVersion 方法
·GetFolder 方法
·GetFolder 方法
·GetFolder 方法
·GetParentFolderName 方法
·GetParentFolderName 方法
·GetParentFolderName 方法
·GetSpecialFolder 方法
·GetSpecialFolder 方法
·GetSpecialFolder 方法
·GetTempName 方法
·GetTempName 方法
·GetTempName 方法
·MoveFile 方法
·MoveFile 方法
·MoveFile 方法
·MoveFolder 方法
·MoveFolder 方法
·MoveFolder 方法
·Type 属性
·Type 属性
·Type 属性
·GetObject 函数
·GetObject 函数
·ScriptEngine 函数
·ScriptEngineBuildVersion 函数
·ScriptEngineBuildVersion 函数
·ScriptEngine 函数
·ScriptEngineMajorVersion 函数
·ScriptEngineMajorVersion 函数
·ScriptEngineMinorVersion 函数
·ScriptEngineMinorVersion 函数
·Add 方法 (Folders)
·Add 方法 (Folders)
·Add 方法 (Folders)
·Files 属性
·Files 属性
·Files 属性
·IsRootFolder 属性
·IsRootFolder 属性
·IsRootFolder 属性
·SubFolders 属性
·SubFolders 属性
·SubFolders 属性
·Microsoft(R) JScript 运行时库参考
·JScript 教程
· 函数
·arguments 属性
·arguments 属性
·arguments 属性
·caller 属性
·caller 属性
·caller 属性
·length 属性 (Function)
·length 属性
·length 属性 (Function)
·escape 方法
·escape 方法
·escape 方法
·eval 方法
·eval 方法
·eval 方法
·Infinity 属性
·Infinity 属性
·Infinity 属性
·isFinite 方法
·isFinite 方法
·isFinite 方法
·isNaN 方法
·isNaN 方法
·isNaN 方法
·NaN 属性 (Global)
·NaN 属性
·NaN 属性
·parseFloat 方法
·parseFloat 方法
·parseFloat 方法
·parseInt 方法
·parseInt 方法
·parseInt 方法
·unescape 方法
·unescape 方法
·unescape 方法
·JScript 比较运算符
·比较运算符
·Microsoft JScript 特性 - ECMA
·Microsoft JScript 特性 - 非-ECMA
·Microsoft Scripting 运行时特性
·abs 方法
·abs 方法
·abs 方法
·acos 方法
·acos 方法
·acos 方法
·asin 方法
·asin 方法
·asin 方法
·atan 方法
·atan2 方法
·atan2 方法
·atan2 方法
·atan 方法
·atan 方法
·ceil 方法
·ceil 方法
·ceil 方法
·cos 方法
·cos 方法
·cos 方法
·E 属性
·E 属性
·E 属性
·exp 方法
·exp 方法
·exp 方法
·floor 方法
·floor 方法
·floor 方法
·LN10 属性
·LN10 属性
·LN10 属性
·LN2 属性
·LN2 属性
·LN2 属性
·log 方法
·LOG10E 属性
·LOG10E 属性
·LOG10E 属性
·LOG2E 属性
·LOG2E 属性
·LOG2E 属性
·log 方法
·log 方法
·max 方法
·max 方法
·max 方法
·min 方法
·min 方法
·min 方法
·PI 属性
·PI 属性
·pow 方法
·pow 方法
·pow 方法
·random 方法
·random 方法
·random 方法
·round 方法
·round 方法
·round 方法
·sin 方法
·sin 方法
·sin 方法
·sqrt 方法
·SQRT1_2 属性
·SQRT1_2 属性
·SQRT1_2 属性
·SQRT2 属性
·SQRT2 属性
·SQRT2 Property
·sqrt 方法
·sqrt 方法
·tan 方法
·tan 方法
·tan 方法
· 方法
·JScript 运行时错误
·JScript 语法错误
·MAX_VALUE 属性
·MAX_VALUE 属性
·MAX_VALUE 属性
·MIN_VALUE 属性
·MIN_VALUE 属性
·MIN_VALUE 属性
·NaN 属性
·NaN 属性
·NaN 属性
·NEGATIVE_INFINITY 属性
·NEGATIVE_INFINITY 属性
·NEGATIVE_INFINITY 属性
·POSITIVE_INFINITY 属性
·POSITIVE_INFINITY 属性
·POSITIVE_INFINITY 属性
· 对象
·ActiveXObject 对象
·ActiveXObject 对象
·Array 对象
·Array 对象
·Array 对象方法
·Array 对象属性
·Boolean 对象
·Boolean 对象
·Boolean 对象方法
·Boolean 对象属性
·Date 对象
·Date 对象
·Date 对象方法
·Date 对象属性
·Dictionary 对象
·Dictionary 对象
·Dictionary 对象方法
·Dictionary 对象属性
·Drive 对象
·Drive 对象
·Drive 对象
·Drive 对象
·constructor 属性
·constructor 属性
·constructor 属性
·prototype 属性
·prototype 属性
·prototype 属性
·toString 方法
·toString 方法
·toString 方法
·valueOf 方法
·valueOf 方法
·valueOf 方法
·Enumerator 对象
·Enumerator 对象
·Enumerator 对象
·Enumerator 对象
·Error 对象
·Error 对象
·Error 对象
·File 对象
·File 对象
·File 对象
·File 对象
·FileSystemObject 对象
·FileSystemObject 对象
·FileSystemObject 对象方法
·FileSystemObject 对象属性
·Folder 对象
·Folder 对象
·Folder 对象
·Folder 对象
·Function 对象
·Function 对象
·Function 对象方法
·Function 对象属性
·Global 对象
·Global 对象
·Global 对象
·Global 对象
·Math 对象
·Math 对象
·Math 对象方法
·Math 对象属性
·Number 对象
·Number 对象
·Number 对象方法
·Number 对象属性
·Object 对象
·Object 对象
·Object 对象
·Object 对象
·RegExp 对象
·RegExp 对象
·RegExp 对象
·RegExp 对象
·正则表达式对象
·正则表达式对象
·正则表达式对象
·正则表达式对象
·String 对象
·String 对象
·String 对象方法
·String 对象属性
·TextStream 对象
·TextStream 对象
·TextStream 对象
·TextStream 对象
·VBArray 对象
·VBArray 对象
·VBArray 对象
·VBArray 对象
· 运算符
·运算符优先级
·JScript 的运算符
·加法运算符 (+)
·加法运算符 (+)
·加法赋值运算符 (+=)
·加法赋值运算符 (+=)
·复合赋值运算符
·逻辑“与”运算符 (&&)
·逻辑“与”运算符 (&&)
·赋值运算符 (=)
·赋值运算符 (=)
·按位“与”赋值运算符 (&=)
·按位“与”赋值运算符 (&=)
·按位“或”赋值运算符 (|=)
·按位“或”赋值运算符 (|=)
·按位“与”运算符 (&)
·按位“与”运算符 (&)
·按位“非”运算符 (~)
·按位“非”运算符 (~)
·按位“或”运算符 (|)
·按位“或”运算符 (|)
·逗号运算符 (,)
·逗号运算符(,)
·条件(三目)运算符 (?:)
·条件(三元)运算符 (?:)
·delete 运算符
·delete 运算符
·除法赋值运算符 (/=)
·除法赋值运算符 (/=)
·除法运算符 (/)
·除法运算符 (/)
·递增 (++) 和递减 (--) 运算符
·递增 (++) 和递减 (--) 运算符
·instanceof 运算符
·instanceof 运算符
·运算符总结
·左移赋值运算符 (<<=)
·左移赋值运算符 (<<=)
·按位左移运算符 (<<)
·按位左移运算符 (<<)
·取余运算符 (%)
·取余赋值运算符 (%=)
·取余赋值运算符 (%=)
·乘法赋值运算符 (*=)
·乘法赋值运算符 (*=)
·乘法运算符 (*)
·乘法运算符 (*)
·new 运算符
·逻辑“非”运算符 (!)
·逻辑“非”运算符 (!)
·逻辑“或”运算符 (||)
·逻辑“或”运算符 (||)
·右移赋值运算符 (>>=)
·右移赋值运算符 (>>=)
·按位右移运算符 (>>)
·按位右移运算符 (>>)
·减法赋值运算符 (-=)
·减法赋值运算符 (-=)
·减法运算符 (-)
·减法运算符 (-)
·typeof 运算符
·typeof 运算符
·无符号右移赋值操作 (>>>=)
·无符号右移赋值运算符 (>>>=)
·无符号右移运算符 (>>>)
·无符号右移运算符 (>>>)
·void 运算符
·void 运算符
·按位“异或”运算符 (^)
·按位“异或”运算符 (^)
·按位“异或”赋值运算符 (^=)
·按位“异或”赋值运算符 (^=)
· 属性
·description 属性
·description 属性
·description 属性
·number 属性
·number 属性
·number 属性
·index 属性
·index 属性
·index 属性
·input 属性
·input 属性
·input 属性
·lastIndex 属性
·lastIndex 属性
·lastIndex 属性
·$1...$9 属性
·$1..$9 属性
·$1...$9 属性
·compile 方法
·compile 方法
·compile 方法
·exec 方法
·exec 方法
·exec 方法
·lastIndex 属性(正则表达式)
·lastIndex 属性(正则表达式)
·lastIndex 属性(正则表达式)
·source 属性
·source 属性
·source 属性
·test 方法
·test 方法
·test 方法
·正则表达式的语法
·正则表达式的语法
·正则表达式的语法
·JScript 的保留关键字
· 字母顺序的关键字列表
· 特性信息
· 方法
· 对象
· 属性
· 语句
·break 语句
·break 语句
·@cc_on 语句
·@cc_on 语句
·Comment 语句
·Comment 语句
·@if 语句
·@if 语句
·continue 语句
·continue 语句
·do...while 语句
·do...while 语句
·for 语句
·for 语句
·for...in 语句
·for...in 语句
·function 语句
·function 语句
·if...else 语句
·if...else 语句
·Labeled 语句
·Labeled 语句
·return 语句
·return 语句
·@set 语句
·switch 语句
·switch 语句
·this 语句
·this 语句
·throw 语句
·throw 语句
·try...catch 语句
·try...catch 语句
·var 语句
·var 语句
·while 语句
·while 语句
·with 语句
·with 语句
·anchor 方法
·anchor 方法
·anchor 方法
·big 方法
·big 方法
·big 方法
·blink 方法
·blink 方法
·blink 方法
·bold 方法
·bold 方法
·bold 方法
·charAt 方法
·charAt 方法
·charAt 方法
·charCodeAt 方法
·charCodeAt 方法
·charCodeAt 方法
·concat 方法(String)
·concat 方法(字符串)
·concat 方法(字符串)
·fixed 方法
·fixed 方法
·fixed 方法
·fontcolor 方法
·fontcolor 方法
·fontcolor 方法
·fontsize 方法
·fontsize 方法
·fontsize 方法
·fromCharCode 方法
·fromCharCode 方法
·fromCharCode 方法
·indexOf 方法
·indexOf 方法
·indexOf 方法
·italics 方法
·italics 方法
·italics 方法
·lastIndexOf 方法
·lastIndexOf 方法
·lastIndexOf 方法
·length 属性(字符串)
·length 属性(String)
·length 属性(String)
·link 方法
·link 方法
·link 方法
·match 方法
·match 方法
·match 方法
·replace 方法
·replace 方法
·replace 方法
·search 方法
·search 方法
·search 方法
·slice 方法 (String)
·slice 方法 (String)
·slice 方法 (String)
·small 方法
·small 方法
·small 方法
·split 方法
·split 方法
·split 方法
·strike 方法
·strike 方法
·strike 方法
·sub 方法
·sub 方法
·sub 方法
·substr 方法
·substr 方法
·substr 方法
·substring 方法
·substring 方法
·substring 方法
·sup 方法
·sup 方法
·sup 方法
·toLowerCase 方法
·toLowerCase 方法
·toLowerCase 方法
·toUpperCase 方法
·toUpperCase 方法
·toUpperCase 方法
·AtEndOfLine 属性
·AtEndOfLine 属性
·AtEndOfLine 属性
·AtEndOfStream 属性
·AtEndOfStream 属性
·AtEndOfStream 属性
·Close 方法
·Close 方法
·Close 方法
·Column 属性
·Column 属性
·Column 属性
·Line 属性
·Line 属性
·Line 属性
·Read 方法
·Read 方法
·ReadAll 方法
·ReadAll 方法
·ReadAll 方法
·Read 方法
·ReadLine 方法
·ReadLine 方法
·ReadLine 方法
·Skip 方法
·Skip 方法
·Skip 方法
·SkipLine 方法
·SkipLine 方法
·SkipLine 方法
·Write 方法
·Write 方法
·WriteBlankLines 方法
·WriteBlankLines 方法
·WriteBlankLines 方法
·Write 方法
·WriteLine 方法
·WriteLine 方法
·WriteLine 方法
·Microsoft(R) JScript 语言参考
·JScript 教程
·JScript 教程
·数据类型转换
·dimensions 方法
·dimensions 方法
·dimensions 方法
·getItem 方法
·getItem 方法
·getItem 方法
·lbound 方法
·lbound 方法
·lbound 方法
·toArray 方法
·toArray 方法
·toArray 方法
·ubound 方法
·ubound 方法
·ubound 方法
·版本信息
·JScript 的对象
·递归
·变量范围
·FileSystemObject 对象
·FileSystemObject 示例代码
·Microsoft(R) Scripting 库 - FileSystemObject 和 Scripting 运行时库参考的介绍
·设计 FileSystemObject
·Microsoft(R) Scripting 库 - FileSystemObject 对象
·处理驱动器和文件夹
·处理文件
·特殊字符
·编写 JScript 代码
·使用数组
·复制、传递和比较数据
·在浏览器中显示信息
创建高级对象

创建高级对象
 JScript 教程
上一页
下一页



www.51chm.com
使用构造函数来创建对象
在 Microsoft JScript 中,可以使用构造函数来创建和生成对象类。您可以使用 new 语句来调用一个构造函数。该语句将返回其创建的内容。

Function 构造函数这个特例可用来创建匿名的函数。所谓匿名函数是指没有名称的函数。例如,可以使用 Function 构造函数来生成一个 “不工作”的函数,作为在另一个函数内的指示。这种函数只会从一个位置调用,不需要名称。

在下例中,这个匿名函数将生成一行“姓名和电子邮件地址”列表。该函数检查 firstNameFirst 变量的值来决定是先输入名还是姓,然后检查 emailNameFirst 变量的值来决定是先输入姓名还是电子邮件地址。该示例假定已在别的位置设置了firstNameFirstemailNameFirst 的值。

for (j = 1; j < addressList[length]; j++) 
{
oneListingLine = new Function(emailNameFirst, firstNameFirst, addressList, j, theName = new Function(firstNameFirst, addressList, j, var theName=(addressList[j].firstName + addressList[j].lastName); 
if(firstNameFirst)
      {
      theName=(addressList[j].firstName + addressList[j].lastName);
      },) ; 
if (emailNameFirst) 
      {
theListing = addressList[j].emailName+ ":\t" + theName 
      } else theListing = theName + ":\t" + addressList[j].emailName; return theListing;)
document.write(oneListingLine + "<br>");
}
编写构造函数
要编写自己的构造函数,可以在构造函数中使用 this 关键字来引用新创建的对象。该构造函数将初始化该对象。

尽管在下面的示例中构造函数是从 0 索引开始的,但这并不是必选项。例如,如果希望某个参数指明数组或对象的实际索引数,您可以将 1 作为第一个索引开始。 在该示例中,该参数是 extent 来使其区别于由内置的 Array( ) 对象中自动维护的 length 参数。如果编写了给数组添加属性的代码,必需更新 extent 参数(或您自己的对应参数),因为该参数不是由 JScript 维护的。注意即使是这个极端简单的示例也使用了对象(点)和数组(方括号)的标注风格来引用当前对象。

function MakeStringArray(length) {
this.extent = length;
for (iNum = 0; iNum < length; i++) {
this[iNum] = "";
}
}

// 使用该构造函数来创建和初始化一个数组。
myStringArray = new MakeStringArray(63);
使用原型来创建对象
在编写对象定义时,可以使用 prototype 属性来创建由该定义生成且所有对象都具有的属性。原型属性将按引用复制给类中的每个对象,因此这一类中的所有对象的这个属性都相同。不过,可以在一个对象中更改原型属性的值,新的值将覆盖默认值,但仅在该实例中有效。属于这个类的其他对象不受此更改的影响。

使用这个原则,可以给 JScript 语言内部的对象定义附加属性,所有这些对象都具有原型。例如,如果要在计算中使用一个特殊的常数,而在 MathNumber 对象中提供的常数没有包括该常数,则可以自己定义,并对其指定各自的对象原型,或对象类的原型属性。

Math.prototype.Avogadro = 6.0232E23;
function howManyMolecules(wtGrams,molWt) {
return ((wtGrams/molWt)*Math.prototype.Avogadro);
}
document.write("There are " + howManyMolecules(window.prompt("How many grams?",0),window.prompt
("What's the molecular weight?",0)) +
 " molecules in that amount.");
也许还需要指出的一点是,您可以定义一个函数,将其指定为 String.prototype 的一个方法,并在脚本的任何地方随字符串使用该函数。下面的示例假定已有一个在脚本的其他地方定义的、称为 "theElements" 的 元素周期表(Periodic Chart)数组,该数组中包含了元素的符号、名称、原子数以及其他相关信息。

function atomName(theSymbol) {
return(theElements[theSymbol].fullName);
}

String.prototype.atomName = atomName;

function decodeFormula(theFormula) {
var theCurrentPiece = "";
var theDecodedFormula = "";
for (i = 1; i = theFormula.length ; i++);
if (theFormtheCurrentPiece 
// 将公式字符串分为符号和数字的数组。
// 循环该公式数组并装配拆开的字符串。每一项为:
theDecodedFormula += formula[n].number
theDecodedFormula += " ";
theDecodedFormula += formula[n].symbol.prototype.atomName;
theDecodedFormula += " "
// 循环结束。

return theDecodedFormula;
}

decodeFormula(window.prompt("Formula?","Al2O3"));


www.51chm.com
更多内容
·的数据类型
·JScript 的变量
·FileSystemObject 词汇
·JScript 的函数
·JScript 词汇表
· 按字母顺序排列的关键字列表
·运算符操作
·concat 方法 (数组)
·concat 方法 (Array)
·concat 方法 (Array)
    首页 |  友情链接 |  网站地图      京ICP备07034540号    © 2007 www.51chm.com       Powered by xichy{at}163.com