87,904
社区成员
发帖
与我相关
我的任务
分享
var a=new Object();
a.test=function(){
alert("x");
};
a.test2=function(){
alert('test2');
};
//调用
a.test();
a.test2();
//其实就是定义一个变量或者方法里定义变量、方法
//第一种方式
var a=function(){
var t=this;
t.test=function(){
alert("x");
};
};
//调用
new a().test();
//不想每次都要new的话,直接在公用的js文件里写一个new a()
//比如
var x=new a();
//然后其他地方调用就可以直接
x.test();
//第二种方法(其实就是定义json)
var a={
test: function(){
alert("1233");
}
};
//调用
a.test();