/*
方法一
*/
var p = new Object(); //声明对象
//为对象添加属性
p.width=300;
p.height=400;
p.num=4;
p.autotime=3;
//为对象添加方法
p.autoplay=function(){
alert("方法一");
}
p.test=function(){ }
//获取属性对象
alert("方法一:"+p.width)
//执行对象方法
p.autoplay(); /*
方法二
*/
function Play(){
var p = new Object();
//属性
p.width=300;
p.height=400;
p.num=4;
p.autotime=3;
//方法
p.autoplay=function(){
alert("方法二");
}
p.test=function(){ } return p;
} var p1 = Play();//实例对象
alert("方法二:"+p1.width);//获取属性值
p1.autoplay(); //执行方法
//后期仍然可以往对象里面添加属性方法
p1.demo = "hello";
/*
方法三
*/
function Play1(width,height,num){
this.width=width;
this.height=height;
this.num=num;
this.autoplay=function(){
alert("方法三");
}
this.test=function(){ }
}
var p2 = new Play1(33,44,2);//实例化对象
alert("方法三:"+p2.width);
p2.autoplay();
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }