Our_New_Obj = new Constructor ( param1 [,param2] ... [,paramN] );
var myDate = new Date(); //创建一个日期对象
var my myString = new String(); //创建一个字符串对象
var myArray = new Array(1,2,3,4); //创建一个数组对象,该数组中有 4 个元素,分别为 1,2,3,4 。
{ 属性名1:属性值1, 属性名2:属性值2, 属性名3:属性值3, ... }
<script type="text/javascript" language="javascript">
<!--
var cpuinfo = {
fre:1000,
man:"intel",
type:"x86",
core:4
};
document.write("CPU 频率: ", cpuinfo.fre, "Mhz", "<br>");
document.write("CPU 厂商: ", cpuinfo.man, "<br>");
document.write("CPU 类型: ", cpuinfo.type, "<br>");
document.write("CPU 核心: ", cpuinfo.core, "个", "<br>");
-->
</script>
CPU 频率: 1000Mhz
CPU 厂商: intel
CPU 类型: x86
CPU 核心: 4个
new Function(statement)
report:new Function("document.write('测试报告:这个 CPU 超频能力很不错')")
function cpuinfo()
{
this.fre = 1000;
this.man = "intel";
this.type = "x86";
this.core = 4;
}
var mycpu1 = new cpuinfo();
var mycpu2 = new cpuinfo();
function cpuinfo (_fre, _man, _type, _core)
{
this.fre = _fre;
this.man = _man;
this.type = _type;
this.core = _core;
}
var mycpu = new cpuinfo(3200, "AMD", "x86", 8);
function Our_Report()
{
alert("测试报告:这个 CPU 超频能力很不错");
}
function cpuinfo (_fre, _man, _type, _core)
{
this.fre = _fre;
this.man = _man;
this.type = _type;
this.core = _core;
this.report = Our_Report;
}
<!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> 构造函数 </title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<script type="text/javascript" language="javascript">
<!--
function Our_Report()
{
alert("测试报告:这个 CPU 超频能力很不错");
}
function cpuinfo (_fre, _man, _type, _core)
{
this.fre = _fre;
this.man = _man;
this.type = _type;
this.core = _core;
this.report = Our_Report;
}
var mycpu = new cpuinfo(3200, "AMD", "X86", 8);
document.write("CPU 频率: ", mycpu.fre, "Mhz", "<br>");
document.write("CPU 厂商: ", mycpu.man, "<br>");
document.write("CPU 类型: ", mycpu.type, "<br>");
document.write("CPU 核心: ", mycpu.core, "个", "<br>");
//引用 mycpu 对象的 report() 方法
mycpu.report();
-->
</script>
</body>
</html>
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |