<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不管用吗?
解决方案 »
- extjs怎样在internet中打log
- 推荐个好点的javascript调试工具 谢啦最好附上大体说明
- 急急急.请问this对象问题?
- js的全局变量的问题
- ocx 控件 如何给同一页面的<input> 传值
- jquery 合并列的时候根据前一列合并 后一列的单元格合并范围不能超过前一列的合并范围 如果某一列没有合并的 后面的所有列都不合并 高手帮忙啊
- 有关时间格式,怎么改变(on line)
- 急: 怎么样屏蔽错误提示框??
- 怎样写一个按钮清空file对象?
- javascript和jquery
- 分享:自己翻译的 Prototype 1.6.0.3 中文参考手册,散分
- 向大家请教2个关于单选按钮获得值和跳转的问题!多谢!
改为
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>