来了兴致,继续写一个javascript的构造函数。
function Abc(attr1,attr2,method1){
this.attr1 = attr1;
this.attr2 = attr2;
this.method1 = method1;
this.showAttr = function(){
this.method1();
alert("{[attr1:"+this.attr1+",attr2:"+this.attr2+"]}");
}
}
var abc = new Abc("LV1","LV2",function(){
alert("show:)");
});
abc.showAttr();
返回的结果是先弹出show:)对话框,再弹出{[attr1:LV1,attr2:LV2]}对话框。
本文介绍了一个使用JavaScript编写的构造函数示例,展示了如何定义对象属性和方法,并通过实例化对象来调用这些方法。
4811

被折叠的 条评论
为什么被折叠?



