web前端|js教程
Javascript,自定义,js
web前端-js教程
Javascript常用自定义类型、属性、方法整理,需要的朋友可以参考下。
网站演示在线自适应测试源码,ubuntu 运维手册,tomcat文件夹如何删除,爬虫图片源码,php格式文件怎么打开图文,cpa,seo,semlzw
1. 定义类型
数据帧封装 源码,ubuntu装kde桌面,怎么用electron爬虫,php requery,seo伪造快照lzw
function UserObject(parameter) { }
parameter 可省略,相当于C#中构造函数参数。
2. 实例化自定义类型
微擎的源码好用吗,ubuntu查看网卡参数,爬虫淘宝所有商品,php参数长度,seo入门优化lzw
function userobject(parameter){ } //myobject is now an object of type userobject! var myobject=new userobject("hi") alert(myobject)
3. 添加属性
function userobject(parameter){ this.firstproperty=parameter this.secondproperty="This is the second property" }
//使用
var myobject=new userobject("hi there.") //alerts "hi there." alert(myobject.firstproperty) //writes "This is the second property" document.write(myobject.secondproperty)
4.添加方法 (circle类)
//first method function function computearea(){ var area=this.radius*this.radius*3.14 return area } //second method function function computediameter(){ var diameter=this.radius*2 return diameter }
关联到自定义类型:
/*the below creates a new object, and gives it the two methods defined earlier*/ function circle(r){ //property that stores the radius this.radius=r this.area=computearea this.diameter=computediameter }
使用自定义方法:
var mycircle=new circle(20) //alerts 1256 alert("area="+mycircle.area()) //alerts 400 alert("diameter="+mycircle.diameter())