首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

js种、实例对象

2012-11-23 
js类、实例对象一 、js类1) 定义:function cP(id,name){??? ??? this.id id??? this.name name??? thi

js类、实例对象

一 、js类

1) 定义:


function cP(id,name){
???
??? this.id = id;
??? this.name = name;
??? this.method = function(){alert("hello");};
}

2) 给cP类添加属性:


cP.prototype.method1 = function){alert("this is another method of cP");};

3) cP类调用:


var v = new cP(3,"jack");



二、js实例对象

1) 定义


? 1.1) var o = {
???????????? i:4,
???????????? method:function(){alert("hello");}
??????? };


?1.2) var o = new Object();
??????????? o.i = 4;
??????????? o.method = function(){alert("hello");
????? };


?1.3) var o = {};
??????????? o.i = 4;
??????????? o.method = function(){alert("hello");
????? };

2) 调用


o.method();

热点排行
Bad Request.