来了兴致,继续写一个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]}对话框。