构建一个 Javascript 多维数组构造器, By shawl.qiu
说明:
首先嘛, JS 的数组是一维的...
如果咱想创建一个多维数组的话, 那就得在数组元素中 创建数组...
大部分时候这样是无可厚非的.
如果在明确知道需要N维数组的情况下, 还用这种麻烦的方法...
那太不人性化了...
所以鄙人就构造了这么一个多维数组构造器...希望能方便多维数组的操作.
shawl.qiu
2007-09-19
http://blog.csdn.net/btbtd
演示:
http://files.myopera.com/btbtd/web/Multi-Array_Constructor.htm
内容:
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template </title>
<style type="text/css">
/* <![CDATA[ */
/* ]]> */
</style>
<script type="text/javascript">
/*<![CDATA[*/
if (navigator.appName=="Microsoft Internet Explorer")
{
//最大化窗口
self.moveTo(-5,-5)
self.resizeTo(screen.availWidth +8,screen.availHeight+8)
//这个脚本定义的宽度其实比原窗口还要大那么一点.
}
/*]]*/
</script>
</head>
<body>
<script type="text/javascript">
/*<![CDATA[*/
var Ar = fArray(2, 3, 4)
document.write(Ar.length+" "+Ar[0].length+" "+Ar[0][0].length+" "+typeof(Ar[0][0][0]), "<br/>");
var Ar = fArray(10, 10)
document.write(Ar.length+" "+Ar[0].length+" "+typeof(Ar[0][0]), "<br/>");
//alert(Ar.length)
function fArray()
{ // shawl.qiu code, return array; Func: fGetArg
var Len = arguments.length;
if(Len===0) return [];
var Arg = fGetArg.apply(this, arguments);
//alert(Arg.slice(1))
var Ar = new Array(arguments[0]);
for(var i=0, j=arguments[0]; i<j; i++)
{
if(Len>1)
Ar[i] = fArray.apply(null, Arg.slice(1))
} // end for
if(typeof(Ar[0])=="undefined")
{
var Count = Ar.length;
for(var i=0; i<Count; i++)
Ar[i] = "";
}
return Ar;
} // end function fArray()
function fGetArg()
{ // shawl.qiu code, return array
var Ar = [];
var Len = arguments.length;
for(var i=0; i<Len; i++)
{
Ar[i] = arguments[i];
}
return Ar;
} // end function fGetArg()
/*]]*/
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template </title>
<style type="text/css">
/* <![CDATA[ */
/* ]]> */
</style>
<script type="text/javascript">
/*<![CDATA[*/
if (navigator.appName=="Microsoft Internet Explorer")
{
//最大化窗口
self.moveTo(-5,-5)
self.resizeTo(screen.availWidth +8,screen.availHeight+8)
//这个脚本定义的宽度其实比原窗口还要大那么一点.
}
/*]]*/
</script>
</head>
<body>
<script type="text/javascript">
/*<![CDATA[*/
var Ar = fArray(2, 3, 4)
document.write(Ar.length+" "+Ar[0].length+" "+Ar[0][0].length+" "+typeof(Ar[0][0][0]), "<br/>");
var Ar = fArray(10, 10)
document.write(Ar.length+" "+Ar[0].length+" "+typeof(Ar[0][0]), "<br/>");
//alert(Ar.length)
function fArray()
{ // shawl.qiu code, return array; Func: fGetArg
var Len = arguments.length;
if(Len===0) return [];
var Arg = fGetArg.apply(this, arguments);
//alert(Arg.slice(1))
var Ar = new Array(arguments[0]);
for(var i=0, j=arguments[0]; i<j; i++)
{
if(Len>1)
Ar[i] = fArray.apply(null, Arg.slice(1))
} // end for
if(typeof(Ar[0])=="undefined")
{
var Count = Ar.length;
for(var i=0; i<Count; i++)
Ar[i] = "";
}
return Ar;
} // end function fArray()
function fGetArg()
{ // shawl.qiu code, return array
var Ar = [];
var Len = arguments.length;
for(var i=0; i<Len; i++)
{
Ar[i] = arguments[i];
}
return Ar;
} // end function fGetArg()
/*]]*/
</script>
</body>
</html>