<html>
<body>
<script>
Object.color="GREEN";
function A()
{
// this.prototype.color="RED";
// this.color='BLUE';
alert(this.color);
}A();
</script>
</body>
</html>为什么弹出undefined?不是从原型链最终都可以找到Object吗?
另外
<html>
<body>
<script>
function A()
{
this.prototype.color="RED";
alert(this.color);
}A();
</script>
</body>
</html>
为什么什么都不弹出来呢?this.prototype不管用吗?
<body>
<script>
Object.color="GREEN";
function A()
{
// this.prototype.color="RED";
// this.color='BLUE';
alert(this.color);
}A();
</script>
</body>
</html>为什么弹出undefined?不是从原型链最终都可以找到Object吗?
另外
<html>
<body>
<script>
function A()
{
this.prototype.color="RED";
alert(this.color);
}A();
</script>
</body>
</html>
为什么什么都不弹出来呢?this.prototype不管用吗?
改为
Object.prototype.color = "GREEN";另,直接 A(); 时 this === window,而 new A() 才是实例化对象!lz 的概念一塌糊涂,多读读书!L@_@K
Object.prototype.color = "GREEN";
function A()
{
// this.prototype.color="RED";
// this.color='BLUE';
//alert(this.color);
} alert((new A()).color); // GREEN第二段的错误在于,不能在类定义中使用 prototype,lz 的写法相当于增加了实例属性,而非扩展 prototype!L@_@K
function A()
{
alert(this.color);
}
A.prototype.color="RED"; new A(); // RED
<script>
function A() {
alert(this == window); // true
}
A();
</script>
这种情况下,是window对象调用了A();所以A函数中的this其实是window函数同时可以作为一个对象构造器,new一个新对象,这this才是该对象
<script>
function A() {
this.color = "Blue";
}
var a = new A();
alert(a.color);
</script>
show是被a对象调用的,所以show函数中的this就是a<script>
function A() {
this.color = "Blue";
}
A.prototype.show = function() {
alert(this.color);
}
var a = new A();
a.color += ",Red";
a.show();
</script>