想定义一个对象,其中有个属性是集合属性。不知如何定义。请指教!如: 任务列表var TaskList=function()
{
this.name="aaa";
this.descript="aaaaa";
//请问这个属性里有若干个对象应该如何定义!
this.node={task1,task2.....}
//
}
{
this.name="aaa";
this.descript="aaaaa";
//请问这个属性里有若干个对象应该如何定义!
this.node={task1,task2.....}
//
}
Array 是 JavaScript 中的内建对象;
而 JScript 中有 collection 的概念,通常会有 item 方法和 length 属性:L@_@K
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="[email protected]" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
<script type="text/javascript">
<!--
function WriteLine(contents) {
document.write(contents + "<br />");
}// Retrieves an object from the all collection or various other collections.
var allElements = document.body.all;WriteLine(typeof(allElements)); // object
WriteLine(allElements.constructor); // undefined
WriteLine(allElements instanceof Array); // false
WriteLine(allElements.length); // 4
//-->
</script>
</body>
</html>
Web 开发常用手册DHTML 参考手册
http://download.csdn.net/source/308913JScript 语言参考
http://download.csdn.net/source/308916CCS 样式表中文手册
http://download.csdn.net/source/304124
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="[email protected]" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
<script type="text/javascript">
<!--
function WriteLine(contents) {
document.write(contents + "<br />");
}// 声明数组实例。
var allElements = ["node1", "node2", "node3", "node4"];WriteLine(typeof(allElements)); // object
WriteLine(allElements.constructor); // function Array() { [native code] }
WriteLine(allElements instanceof Array); // true
WriteLine(allElements.length); // 4
//-->
</script>
</body>
</html>
类似这样的:
var allElements = ["node1", "node2", "node3", "node4"];
好像已经定义好了!
var allElements = ["node1", "node2", "node3", "node4"];
allElements.push("node5");
allElements.push("node6");
alert(allElements.length); // 6Web 开发常用手册DHTML 参考手册
http://download.csdn.net/source/308913JScript 语言参考
http://download.csdn.net/source/308916CCS 样式表中文手册
http://download.csdn.net/source/304124