var F=function(){
this.a=""
this.display=function(){
alert("111111");
}
}
这样一个对象是这么构造的。。
var f=new F();
然后再使用。。
如果现在要变成这样怎么办?
var E=function(){
this.F=function(){
this.a=""
this.display=function(){
alert("111111");
}
}
}
要如何构造呢?
this.a=""
this.display=function(){
alert("111111");
}
}
这样一个对象是这么构造的。。
var f=new F();
然后再使用。。
如果现在要变成这样怎么办?
var E=function(){
this.F=function(){
this.a=""
this.display=function(){
alert("111111");
}
}
}
要如何构造呢?
var E=function(){
this.F=function(){
this.a=""
this.displayF=function(){
alert("111111");
}
}
this.H=function(){
this.b=""
this.displayH=function(){
alert("2222222");
}
}
} 我现在想适用F这个对象来完成alert("111111").要怎么做呢?
var E=function(){
this.F={
a:"",
displayF:function(){
alert("111111");
}
}
this.H=function(){
this.b=""
this.displayH=function(){
alert("2222222");
}
}
} var e = new E();
e.F.displayF();
var E=function(){
this.F=function(arg){
this.a=arg;
this.displayF=function(){
alert(this.a);
}
}
this.H=function(arg){
this.b=arg
this.displayH=function(){
alert(this.b);
}
}
}
这样怎么输出呢?
var E=function(){
this.F={
a:"",
displayF:function(arg){
alert(arg);
}
}
} var e = new E();
e.F.displayF("test");
e.F.displayF("test");
var E=function(){
this.F=function(arg){
return {
a:"",
displayF:function(arg){
alert(arg);
}
}
}
} var e = new E();
e.F().displayF("test");
this.F=function(arg){
this.a=arg;
this.displayF=function(){
alert(this.a);
}
}
this.H=function(arg){
this.b=arg
this.displayH=function(){
alert(this.b);
}
}
} 这里面F不能带参数呢???
如果要带参数就得拉到里面的函数上去传参数么?
var E=function(){
this.F=function(arg){
return {
a:"",
displayF:function(){
alert(arg);
}
}
}
} var e = new E();
e.F("test").displayF();
var E=function(){
this.F = new F();
} var F = function(){
this.a="";
this.displayF=function(arg){
alert(arg);
}
}var e = new E();
e.F.displayF("test");
最后一种方法偶采纳了比较不错的说
呵呵。。开始我自己也想到一个方法
就是
var E={};
E.F=function(){
this.a="";
this.displayF=function(arg){
alert(arg);
}
}var f=new E.F();
e.F.displayF("test");
不过看了你的代码觉得你的貌似更好。。就决定采纳你的了
分给你咯