【发布时间】:2014-07-17 13:37:54
【问题描述】:
如果我从代码中删除 nothing() 的声明 - 一切都很好。但是为什么扩展 Array 类会破坏 MyClass 的代码呢?
Array.prototype.nothing = function()
{
alert('Morning');
}
function MyClass()
{
var methods = ['hello', 'hey'];
for (var i in methods)
{
this[methods[i]] = function()
{
alert('This is method ' + methods[i]);
}
}
}
var c = new MyClass();
c.hello();
它中断了,因为警报没有显示:
这是方法嘿
但是:
这是方法function() {
警报(“早上”); }
【问题讨论】:
-
中断...出现什么错误?
-
@tymeJV 抱歉,已按问题更新
标签: javascript oop