真是太疑惑了,请大家看看下面的实例及说明var Aa = function(){
this.b = 2;
this.c = "dfd";
return "ghfh";
}
var b = new Aa();
alert(b.c) //弹出"dfd",说明return没起作用,b是一个实例对象。var Aa = function(){
this.b = 2;
this.c = "dfd";
var dd = function(){
return "fdg"
}
return dd;
}
var b = new Aa();
alert(b()) //弹出"fdg",说明return起作用了,b是一个方法,既dd方法。这是为什么奈?
this.b = 2;
this.c = "dfd";
return "ghfh";
}
var b = new Aa();
alert(b.c) //弹出"dfd",说明return没起作用,b是一个实例对象。var Aa = function(){
this.b = 2;
this.c = "dfd";
var dd = function(){
return "fdg"
}
return dd;
}
var b = new Aa();
alert(b()) //弹出"fdg",说明return起作用了,b是一个方法,既dd方法。这是为什么奈?
解决方案 »
- ExtJS 4.1 在IE8里面的问题
- 汉字机内码的显示问题,SOS!!!
- JavaScript增加一行的操作~知道的人写个例子~万分感谢~
- JS变量里如何赋值JS代码呢?
- access查看数值范围的问题,为嘛,显示乱七八糟的?求解!
- my97
- document.cookie可以得到所有最近设置的cookie,那怎么可以得到cookie里每个的name
- 极限问题!!!!!!!谁有通过JS动态增加和删除HTML对象的范例,以及比较BT的JS代码
- 请问JS中如何将表单控件中的值转换成数值形式以便比较大小
- 將字符型轉換為數字型的函數是什麼函數,tks
- 通过css手段,使iframe的宽高度自适应,在线等
- javascript 传值flash 问题
b.c返回的是Aa里的属性c,而不是return的值alert(b())
b是return值,也就是dd方法,b()就是dd()了
var Aa = function(){
this.b = 2;
this.c = "dfd";
return "ghfh";
}
var b = new Aa();
alert(b.c) //弹出"dfd",说明return没起作用,b是一个实例对象。var Aa = function(){
this.b = 2;
this.c = "dfd";
this.dd = function(){
return "fdg"
}
}
var b = new Aa();
alert(b.dd()) //弹出"fdg",说明return起作用了,b是一个方法,既dd方法。
同样是实例化new Aa(),为什么会不一样!!!!
晕。 为什么说return没起作用?
var Aa = function(){
this.b = 2;
this.c = "dfd";
return this.c="ghfh";
}
var b = new Aa();
alert(b.c) //弹出"dfd",说明return没起作用,b是一个实例对象。var Aa = function(){
this.b = 2;
this.c = "dfd";
var dd = function(){
return "fdg"
}
return dd;
}
var b = new Aa();
alert(b()) //弹出"fdg",说明return起作用了,b是一个方法,既dd方法。
this.b = 2;
this.c = "dfd";
return "ghfh";
}
var b = new Aa();
假设这个例子中,return起作用了,那b不就应该是字符串"ghfh"吗?
this.b = 2;
this.c = "dfd";
return "ghfh";
}
var b = new Aa();
alert(Aa().c)
说反了,NEW出来是不可以的
这是小弟刚刚理解下来的,如果仍是错滴,请各位指教。
var Aa = function(){
this.b = 2;
this.c = "dfd";
return "ghfh";
}
var b = new Aa();
alert(Aa())
1. Create a new native ECMAScript object.
2. Set the [[Class]] property of Result(1) to "Object".
3. Get the value of the prototype property of the F.
4. If Result(3) is an object, set the [[Prototype]] property of Result(1) to Result(3).
5. If Result(3) is not an object, set the [[Prototype]] property of Result(1) to the original Object prototype object as described in section 15.2.3.1.
6. Invoke the [[Call]] property of F, providing Result(1) as the this value and providing the argument list passed into [[Construct]] as the argument values.
7. If Type(Result(6)) is Object then return Result(6).
8. Return Result(1).
注意7 8
p.__proto__=Person.prototype;
Aa.call(p);
return (typeof p=='object')?p:Aa;