黄石网站建设

黄石网页设计

黄石网站制作

黄石网络推广

黄石做网站的公司

黄石建站

博强科技

您的当前位置 >> 主页 > 新闻动态 > 网站建设技术 >

网站建设技术

新闻图案

网站制作

js声明对象的方法

中国网络营销推广专家

js声明对象有三种方法:

1.function play(){}
var p=new play();
//添加属性
p.width=300;
p.height=200;
p.num=6;
p.autotime=30;


//添加方法
p.autoplay=function(){
alert('play.......');
}
p.test=function(){
alert('noplay.......');
}
alert(p.width);
p.autoplay();

2.function play(){
var p=new Object();
//添加属性
p.width=300;
p.height=200;
p.num=6;
p.autotime=30;


//添加方法
p.autoplay=function(){
alert('play.......');
alert(p.num);同理于 alert(this.num);//只有静态里面没有this
}
p.test=function(){
alert('noplay.......');
}
return p;
}
var p=play();
alert(p.width);
p.autoplay();

3.function play(width,height,num,autotime){

//添加属性
this.width=width;
this.height=height;
this.num=num;
this.autotime=autotime;


//添加方法
this.autoplay=function(){
alert('play.......');
alert(p.num);同理于 alert(this.num);//只有静态里面没有this
}
this.test=function(){
alert('noplay.......');
}

}
var p=new play();
alert(p.width);
p.autoplay();

这里有一个需要我说明的就是Object这是一个系统自定义的空对象,方便我们的操作。这上面的三种方法,我顺手的是第二种和第三种,我推荐大家使用的也是这两种,希望我们共同来进步,共同来学习

收缩

QQ在线客服

  • 在线咨询
  • 客服001
  • 客服001
  • 售后服务
  • 客服001
黄石建站

QQ在线客服

首 页 新闻动态 案例展示 服务范围 关于我们 联系我们 客户需求 网站地图
电话:13597671188 QQ:494602646 黄石网站建设-博强科技 Copyright © 2013-2014 All Rights Reserved 鄂ICP备12000085号
博强科技版权所有 未经允许不得私自发布转载